简体   繁体   English

最近的Python rtree-它的作用是什么?

[英]Python rtree nearest - what exactly it does?

I have the following setup - it's rtree build on points: 我有以下设置-它是基于点的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)

Now I'm trying to find all points within the certain distance from certain point: 现在,我试图找到距特定点一定距离内的所有点:

max_distance=5
p = (6,4)
list(idx.nearest(p, 5, objects='raw'))

I receive 我收到

[(6, 4), (6, 3), (5, 4), (8, 1), (2, 3), (7, 8)]

The question is - why (3, 1) is not included in the list? 问题是-为什么(3, 1)不包括在列表中? The distance is ~4.24 so it should be included, right? 距离为〜4.24,因此应该包括在内,对吗?

The nearest method "Returns the k-nearest objects to the given coordinates.", that is, it will return the nearest objects independent on its distance. 最接近的方法“将k个最近的对象返回给定坐标。”,即,它将独立于其距离返回最接近的对象。

The distance of objects isn't a parameter of nearest function, as described on Rtree documentation . 对象的距离不是最近函数的参数,如Rtree文档中所述 The second parameter is the number of results that you want. 第二个参数是所需的结果数。 In your case it returns six values because the points (6, 3), (5, 4) has the same distance (1) to the point (6, 4). 在您的情况下,它返回六个值,因为点(6、3),(5、4)与点(6、4)的距离(1)相同。

To obtain the objects in a certain distance you should use the intersection method . 要获取一定距离内的对象,应使用相交方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM