简体   繁体   中英

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

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 .

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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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