gpt4 book ai didi

r - 使用SF包溶解面要素

转载 作者:行者123 更新时间:2023-12-04 08:32:22 25 4
gpt4 key购买 nike

溶解是作为sf方法here讨论的一种常见的地理处理技术。

我正在尝试复制溶解,因为它在ArcGIS中起作用。在ArcGIS中按两个组考虑县。

无论东部半岛是否包含其他单独的多边形,ArcGIS Dissolve命令都会产生两个多边形。像这样:

这是我想在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
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中:它具有两个功能。

关于r - 使用SF包溶解面要素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44314922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com