Dissolve是一种常见的地理处理技术,作为sf方法在这里讨论。
我试图在sf中复制ArcGIS中的溶解功能。以ArcGIS中的两组县为例。
ArcGIS的溶解命令将生成两个多边形,而不管东半岛是否由其他单独的多边形组成。如下所示:
这就是我想要在sf中复制的功能,但是我无法如下所示实现。
我试图在sf中复制ArcGIS中的溶解功能。以ArcGIS中的两组县为例。
ArcGIS的溶解命令将生成两个多边形,而不管东半岛是否由其他单独的多边形组成。如下所示:
![](https://imgur.com/0GnecOc.png)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#create two homogenous spatial groups
nc$group <- ifelse(nc$CNTY_ <= 1980,1,2)
#plot
ggplot() + geom_sf(data=nc, aes(fill = factor(group)))
#dissolve
library(dplyr)#the summarize function is based on the one from dplyr (which may interfere with summarize from other libraries that may be loaded)
nc_dissolve <- nc %>% group_by(group) %>% summarize()
#plot dissolved
ggplot() + geom_sf(data=nc_dissolve, aes(fill = factor(group)))
#Cartographically, it looks like we have two polygons, but there are
#actually several more wrapped up as MULTIPOLYGONS. We can plot these.
t <- nc_dissolve %>% st_cast() %>% st_cast("POLYGON")
ggplot() + geom_sf(data=t, aes(fill=factor(row.names(t))))
注意半岛有多个无关的多边形。
我怎么才能像在ArcGIS中一样只得到两个呢?非常感谢。
summarize
refers to the function fromdplyr
which conflicts withsummarize
fromplyr
- user3386170