Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a function allowing to select/identify polygon that share a line segment with a source polygon

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:

enter image description here

Using gUnionCascaded from rgeos package, I have a second shapefile with the "contour polygon"

enter image description here

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

enter image description here

like image 508
DJack Avatar asked Sep 06 '25 22:09

DJack


1 Answers

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"))
like image 171
DJack Avatar answered Sep 08 '25 10:09

DJack