Rtree: spatial index for Python GIS

Whether for in-memory feature stores, Plone content, or whatever -- we need an index to speed up the search for objects that intersect with a spatial bounding box.

Index Protocol

In a nutshell:

>>> index.add(id=id, bounds=(left, bottom, right, top))
>>> [n for n in index.intersection((left, bottom, right, top))]
[id]

This resembles a subset of the set protocol. add indexes a new object by id. intersection returns an iterator over ids where the node containing the id intersects with the specified bounding box. The intersection method is exact, with no false positives and no missed data.

Installation

Rtree depends on the spatialindex and tools libraries from SpatialIndex. Make the tools library first. Both are easily installed on Linux/UNIX:

$ ./configure; make; make install

After the libraries are installed, you can install the Python package using easy_install

$ easy_install Rtree

Or get the source from the repository and install using the setup script:

$ svn co http://svn.gispython.org/svn/gispy/Rtree/trunk Rtree
$ cd Rtree
$ python setup.py install

This installs an egg. If you'd rather stick with the old-school distributions, use

$ python setup.py install --root / --single-version-externally-managed

Usage

See source:Rtree/trunk/tests/R-Tree.txt.

Performance

See the source:Rtree/trunk/tests/benchmarks.py file for a comparison.

Development Roadmap