2

I m new to python, I m using import rtree library. I m indexin the 2 d dimensional points data into rtree and specifying query box(rectangle). I should get the points which lie inside the query box. But I m getting the nearest point which is out of the query box.

   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)))

but I m getting results which are out of 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]

In the output, you can see that rtree is returning index 1, 8 which close to the outside of the query box. but I need only the points which lie inside the query box. is their any suggestion to get points which lie inside the query box using rtree.

1 Answers1

2

If you want the intersection, use the method intersection.

The method nearest returns the nearest neighbors, as the name indicates.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194