在R中消除多边形要素的边界

3

我一直在寻找现有的R函数,用于聚合同一图层内共享公共边界的多边形要素(即生成类似ArcGIS中'Dissolve Boundaries'工具的输出)。

我使用gdal_polygonizeR从栅格文件创建了一个多边形图层(https://johnbaumgartner.wordpress.com/2012/07/26/getting-rasters-into-shape-from-r/)。其中一些多边形形状由单个栅格单元分隔,因此作为不同的特征存储在shapefile中。 我想将这些多边形要素组合成单个多边形要素,并创建一个新的shapefile(减少多边形元素的总数),最好使用溶解的阈值距离。

是否有人知道在R中完成此操作的现有方法?

更新: 我认为解决方案可能涉及到aggregate,然后是disaggregate。我目前正在探索这一点,特别注意确保具有孔的多边形要素与父多边形相关联(请参见:Split polygon parts of a single SpatialPolygons Object)。如果我找到解决方案,将再次更新。


请点击此处了解更多关于 [tag:sf] 包的信息:https://r-spatial.github.io/sf/reference/geos_combine.html。 - Cristian E. Nuno
3个回答

5
library(raster)
y <- aggregate(x)

谢谢,但是“aggregate”将所有多边形部分合并为一个要素。我希望没有共享边界(接触)的部分仍然作为图层属性表中不同的行存在。是否有“aggregate”中可以实现这一点的其他参数? - Dorothy
1
请参见原问题中的“更新”部分。 - Dorothy

3

使用gdal_polygonizeR(而不是由于运行时问题而使用rasterToPolygon)将光栅文件转换为面要素后,可以通过以下步骤(下面代码中的“poly”)来“溶解”同一图层内单个面要素的边界:

library(raster)
library(sp)

#inspect initial polygon output for number of features
poly       #e.g., features: 360

#aggregate initial polygon output into single multi-part features
#this solves some unrealistic feature separation which resulted from
#the raster to polygon conversion
polya = aggregate(poly, dissolve = TRUE)
polya      #e.g., features: 1

#disaggregate multi-part polygon into separate features
polyd <- disaggregate(polya)
polyd      #e.g., features: 228

#apply a negligible buffer distance around polygon features to combine features 
#that are only connected by one raster corner (and therefore counted 
#incorrectly as distinct features after the above steps)
#and dissolve
polyb <- buffer(polyd, width = 0.001, dissolve = TRUE)
polyb      #e.g., features: 1

#disaggregate multi-part buffered polygon into separate features
polybd <- disaggregate(polyb)
polybd     #e.g., features: 181

这种方法并不完美,因为它生成的多边形要素与原始光栅到多边形输出的面积不完全相等,但这是我迄今为止能想出的最好的解决方案。如果您有更好的解决方案,请评论。


0
请查看答案以回答您的问题。我相信它正在做您所寻找的内容。然而,当使用poly2nb函数时,我遇到了时间问题,因为我的向量非常大。因此,我正在尝试您的解决方案。

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