【发布时间】:2017-10-16 16:29:35
【问题描述】:
我有两个数据框:
-
points包含一系列具有x, y坐标的点。 -
poly包含两个多边形的坐标(我实际上有超过 100 个,但在这里保持简单)。
我希望能够向数据框 points 添加一个名为 Area 的额外列,其中包含点所在的多边形的名称。
poly <- data.frame(
pol= c("P1", "P1","P1","P1","P1","P2","P2","P2","P2", "P2"),
x=c(4360, 7273, 7759, 4440, 4360, 8720,11959, 11440,8200, 8720),
y=c(1009, 9900,28559,28430,1009,9870,9740,28500,28040,9870))
points <- data.frame(
object = c("P1", "P1","P1","P2","P2","P2"),
timestamp= c(1485670023468,1485670023970, 1485670024565, 1485670025756,1485670045062, 1485670047366),
x=c(6000, 6000, 6050, 10000, 10300, 8000),
y=c(10000, 20000,2000,5000,20000,2000))
plot(poly$x, poly$y, type = 'l')
text(points$x, points$y, labels=points$object )
所以基本上在这个例子中,前两行应该有Area= "P1",而最后一个点应该是空白的,因为该点不包含在任何多边形中。
我已尝试使用函数in.out,但无法按照我的描述构建我的数据框。
非常感谢任何帮助!
【问题讨论】: