[英]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
. 我的问题类似于1和2 ,只有我需要在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.