R - 过滤器坐标

2024-05-06

我是 R 新手,我有一个简单的问题(据我看来),但到目前为止我还没有找到解决方案。我有一组(长)2D (x,y) 坐标 - 只是 2D 空间中的点,如下所示:

ID  x   y
1   1758.56 1179.26
2    775.67 1197.14
3   296.99  1211.13
4   774.72  1223.66
5   805.41  1235.51
6   440.67  1247.59
7   1302.02 1247.93
8   1450.4  1259.13
9   664.99  1265.9
10  2781.05 1291.12
etc.....

如何过滤特定区域(任何形状!)中的点(表中的行)?如何过滤指定坐标子集中的点。如何指定想要/不需要的区域子集?那么如何将其放入R中呢? :) 提前谢谢很多!


要检查点是否在任何类型的形状内,请使用inpip的功能splancs包裹。

library(splancs)

set.seed(123)
my.shape <- matrix(runif(10), 5)
my.points <- data.frame(x=runif(500), y=runif(500))
my.points$in.shape <- 1:500 %in% inpip(my.points, my.shape)

plot(my.points[1:2], col=1 + my.points$in.shape)
polygon(my.shape)

要测试多个形状,请将它们放入列表中并使用lapply:

set.seed(127)
multi.shapes <- lapply(1:3, function(...) matrix(runif(6), 3))
my.points$in.multi.shapes <- 1:500 %in%
    unlist(lapply(multi.shapes, function(p) inpip(my.points, p)))
plot(my.points[1:2], col=1 + my.points$in.multi.shapes)
for(p in multi.shapes) polygon(p)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

R - 过滤器坐标 的相关文章

随机推荐