In order to select/identify the border polygons of a shapefile, I would like to use a function able to select/identify polygon that share a line segment with a source polygon.
With figures:
I have this kind of shapefile:
Using gUnionCascaded
from rgeos
package, I have a second shapefile with the "contour polygon"
Now I am looking for a function that can select/identify border polygons (shaded on the fig) i.e. polygons of the first shapefile that share a line segment with the polygon of the second shapefile . :
As proposed by Josh O'Brien, I have used the rgeos::gRelate()
function.
I get 3 DE-9IM cases:
x <- gRelate(shapefile.1, shapefile.2, byid = TRUE)
table(x)
2FF10F212 2FF11F212 2FF1FF212
63 2470 174495
The resulted DE-9IM string codes can be interpreted as follow:
1) 2FF1FF212: represent polygons from the first shapefile that don't intersect the border of the polygon of the second shapefile
2) 2FF11F212: represent polygons from the first shapefile that intersect the border of the polygon of the second shapefile with a line
3) 2FF10F212: represent polygons from the first shapefile that intersect the border of the polygon of the second shapefile with a point
The two last cases are my border polygons that I was looking for. I have got their ID with:
poly.border <- which(x %in% c("2FF10F212","2FF11F212"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With