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

在R中溶解多边形特征的边界,r,aggregate,polygon,spatial,intersect,R,Aggregate,Polygon,Spatial,Intersect,我一直在寻找一个现有的R函数,用于聚合同一层中共享公共边界的多边形特征,即生成输出,如ArcGIS中的“溶解边界”工具 我使用gdal_polygonizeR从光栅文件创建了一个多边形层。某些多边形形状由单个光栅单元分隔,因此作为不同的特征存储在shapefile中。我想将这些多边形特征组合成单个多边形特征,并创建一个新的shapefile,以减少多边形元素的总数,理想情况下使用阈值距离进行溶解 有人知道在R中有这样做的方法吗 更新: 我认为解决方案可能涉及聚合,然后是分解。我目前正在探索这一点

我一直在寻找一个现有的R函数,用于聚合同一层中共享公共边界的多边形特征,即生成输出,如ArcGIS中的“溶解边界”工具

我使用gdal_polygonizeR从光栅文件创建了一个多边形层。某些多边形形状由单个光栅单元分隔,因此作为不同的特征存储在shapefile中。我想将这些多边形特征组合成单个多边形特征,并创建一个新的shapefile,以减少多边形元素的总数,理想情况下使用阈值距离进行溶解

有人知道在R中有这样做的方法吗

更新:
我认为解决方案可能涉及聚合,然后是分解。我目前正在探索这一点,特别注意确保带有孔的多边形特征与父多边形保持关联,请参见:。如果/当我找到解决方案时,将再次更新。

由于运行时问题,使用gdal_polygonizeR NOT rasterToPolygon将光栅文件转换为多边形后,通过应用以下步骤,我已经能够在下面的代码中“溶解”同一层“多边形”中单个多边形特征的边界。注意:我提供了与运行指定函数后输出数据集中特征数量变化相关的输出示例:

library(raster)
y <- aggregate(x)
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

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

由于运行时问题,使用gdal_polygonizeR NOT 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

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

请注意这个问题。我相信它正在做你正在寻找的事情。然而,我在使用poly2nb函数时遇到了时间问题,因为我有非常大的向量。因此,我正在尝试您的解决方案。

请查看您的问题。我相信它正在做你正在寻找的事情。然而,我在使用poly2nb函数时遇到了时间问题,因为我有非常大的向量。因此,我正在尝试您的解决方案。

有关软件包的详细信息,请参见此处:。有关软件包的详细信息,请参见此处:。谢谢,但“聚合”将所有多边形部分合并到一个功能中。我希望不共享边界接触的部分在层的属性表中保留为不同的行。“聚合”中是否有其他参数可以实现这一点?请参阅原始问题中的“更新”,谢谢,但“聚合”将所有多边形部分合并到一个功能中。我希望不共享边界接触的部分在层的属性表中保留为不同的行。“聚合”中是否有其他参数可以实现这一点?请参阅原始问题中的“更新”