R gis: find borders between polygons

Having a polygon shape file, I need to create a polyline shape file containing only the common borders between the polygons (see image).

My question is similar to 1 and 2 , only I need to do this in R. The last such question relates to the solution using the package Shapelyfor python. The analogue Shapelyfor Ris rgeos. Although I could not find a solution with rgeosmyself.


enter image description here

Note: The shapefile with the borders used for illustration was created in ArcGIS using the solution from the same question 1. Now I need to do the same in R.

+3
source share
1 answer

, , , . 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)

enter image description here

+4

Source: https://habr.com/ru/post/1690579/


All Articles