问题描述
为了选择/识别shapefile的边界多边形,我想使用一个能够选择/识别与源多边形共享线段的多边形的函数.
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.
有数字:
我有这种shapefile:
I have this kind of shapefile:
使用rgeos
包中的gUnionCascaded
,我还有一个带有轮廓多边形"的shapefile.
Using gUnionCascaded
from rgeos
package, I have a second shapefile with the "contour polygon"
现在我正在寻找一个可以选择/识别边界多边形(在图上阴影)的函数,即与第二个shapefile的多边形共享线段的第一个shapefile的多边形. :
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 . :
推荐答案
正如Josh O'Brien所建议的那样,我使用了rgeos::gRelate()
函数.我收到3个DE-9IM案件:
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
产生的DE-9IM字符串代码可以解释如下:
The resulted DE-9IM string codes can be interpreted as follow:
1)2FF1FF212:表示第一个shapefile中的多边形与第二个shapefile中的多边形的边界不相交
1) 2FF1FF212: represent polygons from the first shapefile that don't intersect the border of the polygon of the second shapefile
2)2FF11F212:表示第一个shapefile中的多边形,该多边形与第二个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:表示第一个shapefile中的多边形,该多边形与第二个shapefile中的多边形的边界与点相交
3) 2FF10F212: represent polygons from the first shapefile that intersect the border of the polygon of the second shapefile with a point
最后两种情况是我要寻找的边界多边形.我有他们的ID:
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"))
这篇关于寻找一种功能,该功能允许选择/识别与源面共享线段的面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!