我正在尝试使用R的terra::nearest()函数,但我无法理解输出格式,以及如何实际确定哪个点最近!下面是一个简单的例子:
> dest <- terra::vect(data.frame(x = c(0, 0, 5, 5), y = c(0, 5, 0, 5), attr = 1:4), geom = c("x", "y"))
> src <- terra::vect(data.frame(x = c(3, 1, 2), y = c(2, 3, 1)), geom = c("x", "y"))
> near_ret <- terra::nearest(src, dest)
> print(near_ret)
class : SpatVector
geometry : points
dimensions : 3, 7 (geometries, attributes)
extent : 0, 5, 0, 5 (xmin, xmax, ymin, ymax)
coord. ref. :
names : from_id from_x from_y to_id to_x to_y distance
type : <num> <num> <num> <num> <num> <num> <num>
values : 1 3 2 1 5 0 2.828
2 1 3 2 0 5 2.236
3 2 1 3 0 0 2.236好的,所以to_x、to_y和distance列对我来说是有意义的,而且看起来是正确的。但是to_id对我来说没有任何意义。我本以为该列将索引包含到dest中,但显然没有,因为dest[1, ]是(0, 0)而不是(5, 0)。
我在这里的最终目标是求出最接近每个attr点的dest点的src值。如何找到最近的dest点,以便查找它的attr值?
(这是使用terra版本的1.3-4)
发布于 2021-09-28 23:57:08
这个错误是在terra版本1.4-4中修复的。
https://stackoverflow.com/questions/69168517
复制相似问题