r gis: find borders between polygons

六月ゝ 毕业季﹏ 提交于 2019-12-07 19:39:51

问题


Having a polygon shapefile, I need to produce a polyline shapefile containing only the common borders between polygons (see the picture).

My question is similar to 1 and 2, only I need to do this in R. The latter similar question refers to a solution with the use of Shapely package for python. The analogue of Shapely for R is rgeos. Though, I couldn't find the solution with rgeos on my own.


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.


回答1:


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.

For my small EU subset eusub, I can do this with:

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)



来源:https://stackoverflow.com/questions/35794772/r-gis-find-borders-between-polygons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!