2

我是 python 新手,我正在使用 import rtree 库。我将二维点数据索引到 rtree 并指定查询框(矩形)。我应该得到位于查询框内的点。但我得到了查询框中最近的点。

   My code is below
   from rtree import index
   idx = index.Index()
   left, bottom, right, top = (0.0, 0.0, 1.0, 1.0)
   idx.insert(0, (1,2))
   idx.insert(1, (8,2))
   idx.insert(2, (6,2))
   idx.insert(3, (1,2))
   idx.insert(4, (2,2))
   idx.insert(5, (3,2))
   idx.insert(6, (7,2))
   idx.insert(7, (1,2))
   idx.insert(8, (8,2))
   idx.insert(9, (6,2))
    query_box = [100,29,144,90]
    list(idx.nearest((query_box)))

但我得到的结果超出了查询框。

from rtree import index
idx = index.Index()
left, bottom, right, top = (0.0, 0.0, 1.0, 1.0)
idx.insert(0, (1,2))
idx.insert(1, (8,2))
idx.insert(2, (6,2))
idx.insert(3, (1,2))
idx.insert(4, (2,2))
idx.insert(5, (3,2)) 
idx.insert(6, (7,2))
idx.insert(7, (1,2))
idx.insert(8, (8,2))
idx.insert(9, (6,2))  
query_box = [100,29,144,90]   
list(idx.nearest((query_box)))
Out[142]: [1, 8]

在输出中,您可以看到 rtree 返回接近查询框外部的索引 1、8。但我只需要查询框中的点。他们有什么建议可以使用 rtree 获取位于查询框内的点。

4

1 回答 1

2

如果你想要交集,使用方法intersection

顾名思义,该方法nearest返回最近的邻居。

于 2019-07-09T06:16:06.700 回答