简体   繁体   English

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

[英]r gis: find borders between polygons

Having a polygon shapefile, I need to produce a polyline shapefile containing only the common borders between polygons (see the picture). 有了一个多边形shapefile,我需要生成一个折线shapefile,它只包含多边形之间的公共边框(见图)。

My question is similar to 1 and 2 , only I need to do this in R . 我的问题类似于12 ,只有我需要在R执行此操作。 The latter similar question refers to a solution with the use of Shapely package for python . 后一个类似的问题是指使用Shapely包for python的解决方案。 The analogue of Shapely for R is rgeos . Shapely for R的类似物是rgeos Though, I couldn't find the solution with rgeos on my own. 虽然,我自己找不到rgeos的解决方案。


在此输入图像描述

Note: the shapefile with borders used for illustration was produced in ArcGIS using the solution from similar question 1. Now I need to do the same in R . 注意:带有用于插图的边框的shapefile是使用类似问题1的解决方案在ArcGIS中生成的。现在我需要在R执行相同的操作。

What you want is the lines that are the difference between the set of lines from the dissolved regions and the lines of the regions themselves. 你想要的是从溶解区域的线组和区域本身的线之间的差异线。 IN the rgeos package, gUnaryUnion will dissolve the polygons, and gDifference will subtract. rgeos包中, gUnaryUnion将解散多边形, gDifference将减去。

For my small EU subset eusub , I can do this with: 对于我的小欧盟子集eusub ,我可以这样做:

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

Note the need to convert polygons to lines because the output will be lines. 注意需要将多边形转换为线,因为输出将是线。

Then see this: 然后看到这个:

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

在此输入图像描述

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

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