我有两个代表邻近县的shapefile。我想在R的ggplot中清理它们的公共边界。我知道在ArcGIS中有一种简单的方法可以做到这一点,但我更喜欢坚持使用R.我找到了spdep包并尝试使用它:
ob <- SpatialPolygons(ob@polygons, proj4string=ob@proj4string)
ob2<- SpatialPolygons(ob2@polygons, proj4string=ob2@proj4string)
poly2nb(pl=list(ob,ob2))
但是这导致了以下错误:
错误:extends(class(pl),“SpatialPolygons”)不是TRUE
答案 0 :(得分:1)
我们没有您的文件,但这里有类似的内容:
# devtools::install_github("walkerke/tigris")
library(sp)
library(Matrix)
library(spdep)
library(tigris)
me <- counties("maine", detailed=FALSE)
nh <- counties("nh", detailed=FALSE)
neighbors <- poly2nb(as.SpatialPolygons.PolygonsList(c(me@polygons, nh@polygons)))
neighbors
## Neighbour list object:
## Number of regions: 26
## Number of nonzero links: 114
## Percentage nonzero weights: 16.86391
## Average number of links: 4.384615