See the tests/benchmarks.py file for a comparison of various query methods and how much acceleration can be obtained from using Rtree.
There are a few simple things that will improve performance.
This will substantially (orders of magnitude in many cases) improve performance over insert() by allowing the data to be pre-sorted
>>> def generator_function(): ... for i, obj in enumerate(somedata): ... yield (i, (obj.xmin, obj.ymin, obj.xmax, obj.ymax), obj) >>> r = index.Index(generator_function())
After bulk loading the index, you can then insert additional records into the index using insert()
>>> import cPickle, rtree >>> class FastRtree(rtree.Rtree): ... def dumps(self, obj): ... return cPickle.dumps(obj, -1) >>> r = FastRtree()
>>> objs = r.intersection((xmin, ymin, xmax, ymax), objects="raw")
Adjust rtree.index.Property appropriate to your index.
Don’t use more dimensions than you actually need. If you only need 2, only use two. Otherwise, you will waste lots of storage and add that many more floating point comparisons for each query, search, and insert operation of the index.