r gis:找到多边形之间的边界

r gis: find borders between polygons

有了多边形 shapefile,我需要生成一个仅包含多边形之间公共边界的折线 shapefile(见图)。

我的问题和1 and 2类似,只是我需要在R中这样做。后一个类似的问题是指使用 Shapelypython 的解决方案。 Shapely 对应 R 的类似物是 rgeos。虽然,我自己找不到 rgeos 的解决方案。


注意: 用于插图的带有边框的 shapefile 是在 ArcGIS 中使用类似问题 1 的解决方案生成的。现在我需要在 R 中执行相同的操作。

您想要的是溶解区域的线集与区域本身的线之间的差异线。在rgeos包中,gUnaryUnion会溶解多边形,gDifference会减去。

对于我的小型欧盟子集 eusub,我可以使用:

library(rgeos); library(sp)
borders = gDifference(
   as(eusub,"SpatialLines"),
   as(gUnaryUnion(eusub),"SpatialLines"),
   byid=TRUE)

请注意需要将多边形转换为线,因为输出将是线。

然后看这个:

plot(eusub)
plot(borders, col="red",lwd=2,add=TRUE)