如果我有一组这样创建的 SpatialPolygons:
library(sp)
Sr2 = Polygon(cbind(c(2,2,1,2,4,4,2),c(2,6,7,7,5,3,2)))
Sr3 = Polygon(cbind(c(4,4,2,5,10,4),c(5,3,2,2,5,5)))
Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE)
Srs2 = Polygons(list(Sr2), "s2")
Srs3 = Polygons(list(Sr3, Sr4), "s3/4")
SpP = SpatialPolygons(list(Srs2, Srs3), 1:2)
plot(SpP, col = 2:3, pbg = "white")
这样它看起来像这样:
以及由以下方法创建的点向量:
x <- c(2, 1, 3, 4, 2, 2)
y <- c(2, 4, 2, 2, 3, 4)
points <- cbind(x, y)
如何检测哪些点位于哪个多边形内(如果有)?
谢谢
最佳答案
您可以使用over()
:
over(SpatialPoints(points), SpP)
# 1 2 3 4 5 6
# 2 NA 2 2 1 1
plot(SpP, col = 2:3, pbg = "white", axes=TRUE)
plot(SpatialPoints(points), pch=as.character(1:6), add=TRUE)
关于r - 对于一系列不规则形状的点和一组空间多边形,如何检测哪些点位于哪个多边形内?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28979382/