溶解是一种常见的地理处理技术,作为 SF 方法进行讨论here https://github.com/edzer/sfr/issues/290.
我正在尝试复制溶解,因为它在 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 那样只有两个呢?非常感谢。
我不太熟悉ArcGIS如何定义多边形,但多边形的简单要素访问(ISO标准)规范是一个带有零个或多个表示孔的内环的单环。这意味着,根据该规范,如果您拥有主陆地+几个岛屿,则您没有一个多边形。为了将这些表示为单个特征,相应的几何类型是多多边形。这意味着你的答案在nc_dissolve
: 它有两个特点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)