使用 sf 包溶解多边形特征 [英] Dissolving polygon features with the sf package

查看:34
本文介绍了使用 sf 包溶解多边形特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

融合是一种常见的地理处理技术,在此处讨论为一种 sf 方法.

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

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

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

ArcGIS 溶解命令会生成两个多边形,而不管东部半岛由其他单独的多边形组成.像这样:

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

这是我想在 sf 中复制的功能,但我不能如下所示.

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.

在 ArcGIS 的情况下,我如何只得到两个?非常感谢.

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

推荐答案

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

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.

这篇关于使用 sf 包溶解多边形特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆