-1

I have a rtree, which contains points, i.e. where left == right && top == bottom:

...
idx = index.Index()
....
*print list(idx.nearest((rand_point[0], rand_point[1], rand_point[0], rand_point[1])))
...
left, bottom, right, top = (newpoint[0], newpoint[1], newpoint[0], newpoint[1])
idx.insert(i, (left, bottom, right, top))
...

Instead of dots there is some long code which defines 'point', 'newpoint', 'i' and all that is in the loop. A line marked with * returns smth like:

[0L]
[0L]
[2L]
[2L]
[1L]
[4L]
[6L]
[5L].....

The question is how to get a point, i.e. (left, bottom, right, top) knowing this output?

Olga
  • 982
  • 1
  • 11
  • 17

2 Answers2

0

Use

idx.nearest(.... objects="raw")

or

idx.nearest(.... objects=True)

if you want the actual objects, not just the IDs.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
  • I know what the output is. My question is how to access (left, bottom, right, top) knowing this id. I can't find it in Rtree tutorials. – Olga May 05 '14 at 07:57
  • Well, an rtree is not stock functionality of python. How are we to know? Your code above does not give us the API of whatever library you are using there. – Has QUIT--Anony-Mousse May 05 '14 at 08:06
  • Have a look at the documentation of `nearest`, in particular the `objects` parameter. – Has QUIT--Anony-Mousse May 05 '14 at 08:11
  • and? I saw that. As far as I got it's a number of the nearest points which you'd like to get back. How that can help me? – Olga May 05 '14 at 08:30
  • I need smth like that but for nearest function: `hits = idx.intersection((0, 0, 60, 60), objects=True)` `for i in hits:` `if i.id == 4321:` `i.object` `['%.10f' % t for t in i.bbox]` `42` `['34.3776829412', '26.7375853734', '49.3776829412', '41.7375853734' ]` – Olga May 05 '14 at 08:37
0

I found solution:

    nearest_gen = idx.nearest((rand[0], rand[1], rand[0], rand[1]), objects=True)
    nearest_list = list(idx.nearest((rand[0], rand[1], rand[0], rand[1])))
    for j in nearest_gen:
        if j.id == nearest_list[0]:
            j.object
            print ['%.10f' % t for t in j.bbox]
Olga
  • 982
  • 1
  • 11
  • 17