Dissolving polygon features with the sf package

谁说胖子不能爱 提交于 2019-12-20 21:56:32

问题


Dissolve is a common geoproccessing technique discussed as an sf approach here.

I'm trying to replicate dissolve as it functions in ArcGIS. Consider counties by two groups in ArcGIS.

The ArcGIS dissolve command yields two polygons, regardless of the fact that the eastern peninsula consists of additional separate polygons. Like so:

This is the functionality I'd like to replicate in sf, however I cannot as demonstrated below.

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
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))))

Notice the peninsula has multiple extraneous polygons.

How do I wind up with just two as in the ArcGIS case? Many thanks.


回答1:


I am not too familiar with how ArcGIS defines a polygon, but the simple feature access (an ISO standard) specification of a polygon is a single ring with zero or more inner rings denoting holes. This means that under that specification, if you have the main land + a couple of islands, you don't have a single polygon. To represent these as a single feature, the corresponding geometry type is multipolygon. Meaning your answer is in nc_dissolve: it has two features.



来源:https://stackoverflow.com/questions/44314922/dissolving-polygon-features-with-the-sf-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!