[英]how to find nearest point within querybox(query area) using rtree, python
[英]Python rtree nearest - what exactly it does?
我有以下设置-它是基于点的rtree构建:
from collections import defaultdict
from math import sqrt
import rtree.index
points = [(5, 4), (3, 1), (6, 3), (2, 8), (7, 8), (8, 1), (2, 3), (0, 4), (3, 7), (6, 4)]
idx = rtree.index.Rtree()
for i, p in enumerate(points):
idx.insert(i, p+p, p)
现在,我试图找到距特定点一定距离内的所有点:
max_distance=5
p = (6,4)
list(idx.nearest(p, 5, objects='raw'))
我收到
[(6, 4), (6, 3), (5, 4), (8, 1), (2, 3), (7, 8)]
问题是-为什么(3, 1)
不包括在列表中? 距离为〜4.24,因此应该包括在内,对吗?
最接近的方法“将k个最近的对象返回给定坐标。”,即,它将独立于其距离返回最接近的对象。
对象的距离不是最近函数的参数,如Rtree文档中所述 。 第二个参数是所需的结果数。 在您的情况下,它返回六个值,因为点(6、3),(5、4)与点(6、4)的距离(1)相同。
要获取一定距离内的对象,应使用相交方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.