I have been trying to debug some strange behaviour in a software package that uses Pythons RTree version 0.8.2.
In order to trace the problem, I need to serialize the RTree instance every few minutes, and when the problem happens I can have a pretty accurate snapshot of the RTree.
I am using the following code for the dump:
def _dump_tree(self, filename, tree):
dump_file = Rtree(filename)
for item in tree.intersection(tree.bounds, objects=True):
dump_file.insert(item.id, item.bbox, item.object)
Just open the RTree from the same filename:
>>> from rtree import index >>> idx = index.Index('2015-10-01---14-21-16_items') >>> idx.count(idx.bounds) 42 # The number of items you had in the original tree