Akbar Akbar - 1 year ago 112
Python Question

How to modify object in Python's Rtree index

I've been using a package called Rtree version 0.8.2 which lets you put geospatial objects into an index and perform searches very quickly.
However, I have faced a problem trying to modify already created index.

So there is an insert method that allows you to add object into index:

from rtree import index
idx = index.Index()
idx.insert(1, (left, bottom, right, top),
obj = {'field1': 'value1', 'field2': 'value2'})

And also there is a delete method that allows you to delete unnecessary object from index:

idx.delete(1, (left, bottom, right, top))

Unfortunately, in the package's manual I couldn't find any information about how to modify existing object which is already in the index.

I am particularly curious how to add another field into an obj property, which is represented as a dict (like 'field3': 'value3').

Answer Source

You need to

  1. delete the old object
  2. insert the new object

There is nothing wrong with doing this; it may help improve the tree structure.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download