使用sf包将多边形要素溶解

18
Dissolve是一种常见的地理处理技术,作为sf方法在这里讨论。
我试图在sf中复制ArcGIS中的溶解功能。以ArcGIS中的两组县为例。
ArcGIS的溶解命令将生成两个多边形,而不管东半岛是否由其他单独的多边形组成。如下所示: 这就是我想要在sf中复制的功能,但是我无法如下所示实现。
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中一样只得到两个呢?非常感谢。


有没有办法只在多边形相互接触或重叠的情况下才消除边界?我的shapefile中有超过36000个多边形,因此逐个指定要溶解的位置不是一个选项。 - tnt
1
summarize refers to the function from dplyr which conflicts with summarize from plyr - user3386170
1个回答

6

我不太熟悉ArcGIS如何定义多边形,但是简单要素访问(ISO标准)规范中多边形的定义是一个单环,带有零个或多个内环表示孔洞。这意味着在该规范下,如果您有主陆地和几个岛屿,则没有单个多边形。为了将它们表示为单个要素,相应的几何类型是多多边形。这意味着您的答案在nc_dissolve中:它有两个要素。


有趣的是ArcGIS偏离了标准。我会想出一个解决方法的。非常感谢您的查看。 - ReginaldMilton
检查ArcGIS是否支持简单要素 - 如果不支持,我会感到惊讶。 - Edzer Pebesma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接