【问题标题】:dissolve boundaries of polygon features in R溶解R中多边形特征的边界
【发布时间】:2018-10-20 23:55:06
【问题描述】:

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

我使用 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)。如果/当我找到解决方案时会再次更新。

【问题讨论】:

标签: r aggregate polygon spatial intersect


【解决方案1】:
library(raster)
y <- aggregate(x)

【讨论】:

  • 谢谢,但“聚合”将所有多边形部分组合成一个特征。我希望不共享边界​​(触摸)的部分在图层的属性表中保留为不同的行。 “聚合”中是否有其他参数可以实现这一目标?
  • 查看原始问题中的“更新”
【解决方案2】:

将栅格文件转换为多边形后(由于运行时问题,使用gdal_polygonizeR而不是rasterToPolygon),我已经能够在同一层内“消除边界”单个多边形要素(下面代码中的“多边形”)通过应用以下步骤(注意:我提供了与运行指定函数后输出数据集中的特征数量相关的示例输出):

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

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

【讨论】:

    【解决方案3】:

    请参阅此answer 来回答您的问题。我相信它正在做你正在寻找的东西。但是,我在使用 poly2nb 函数时遇到了时间问题,因为我有非常大的向量。因此,我正在尝试您的解决方案。

    【讨论】:

      猜你喜欢
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      • 2021-03-05
      • 2016-11-29
      • 1970-01-01
      • 2015-06-07
      相关资源
      最近更新 更多