简体   繁体   English

溶解 R 中多边形特征的边界

[英]dissolve boundaries of polygon features in R

I've been looking for an existing R function(s) for aggregating polygon features within the same layer that share a common boundary (ie, producing output like 'Dissolve Boundaries' tool in ArcGIS).我一直在寻找一个现有的 R 函数,用于在共享公共边界的同一图层内聚合多边形要素(即,在 ArcGIS 中生成类似“溶解边界”工具的输出)。

I created a polygon layer from a raster file using gdal_polygonizeR ( https://johnbaumgartner.wordpress.com/2012/07/26/getting-rasters-into-shape-from-r/ ).我使用 gdal_polygonizeR ( https://johnbaumgartner.wordpress.com/2012/07/26/getting-rasters-into-shape-from-r/ ) 从光栅文件创建了一个多边形图层。 Some of the polygon shapes are separated by a single raster cell, and are therefore stored as distinct features in the shapefile.一些多边形形状由单个栅格单元分隔,因此在 shapefile 中存储为不同的要素。 I want to combine such polygon features into a single polygon feature, and create a new shapefile (reducing the total number of polygon elements), ideally with a threshold distance for dissolving.我想将这些多边形特征组合成单个多边形特征,并创建一个新的 shapefile(减少多边形元素的总数),理想情况下具有用于溶解的阈值距离。

Does anyone know of an existing method for doing this in R?有谁知道在 R 中执行此操作的现有方法?

UPDATE: I think the solution may involve aggregate , followed by disaggregate .更新:我认为解决方案可能涉及aggregate ,然后是disaggregate I am currently exploring this with particular attention to ensuring polygon features with holes remain associated with the parent polygon (see: Split polygon parts of a single SpatialPolygons Object ).我目前正在探索这一点,特别注意确保带孔的多边形特征与父多边形保持关联(请参阅: 拆分单个 SpatialPolygons 对象的多边形部分)。 Will update again if/when I find a solution.如果/当我找到解决方案时将再次更新。

After converting a raster file to polygon (using gdal_polygonizeR NOT rasterToPolygon due to runtime issues), I have been able to 'Dissolve Boundaries' of individual polygon features within the same layer ('poly' in code below) by applying the following steps (NB: I have provided example output related to the number of features in the output datasets change after specified functions are run):将光栅文件转换为多边形后(由于运行时问题使用gdal_polygonizeR NOT rasterToPolygon ),我已经能够通过应用以下步骤(NB :我提供了与运行指定函数后输出数据集中的特征数量变化相关的示例输出):

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

This method is not perfect as it results in polygon features that are not precisely equal in area to the original raster to polygon output, but it's the best I could come up with so far.这种方法并不完美,因为它导致多边形特征的面积与原始栅格到多边形输出的面积不完全相等,但这是迄今为止我能想到的最好方法。 Please comment if you have a better solution.如果您有更好的解决方案,请发表评论。

library(raster)
y <- aggregate(x)

Please see this answer to your question.请参阅此问题的答案 I believe it is doing what you are looking for.我相信它正在做你正在寻找的东西。 However, I am running into time issue when using the poly2nb function, as I have very large vectors.但是,我在使用poly2nb函数时遇到了时间问题,因为我有非常大的向量。 Hence I am trying your solution.因此,我正在尝试您的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM