Skip to main content

R-Tree spatial index for Python GIS

Project description

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:

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

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. Ids can be ints or long ints; index queries return long ints.


First, obtain and install a copy of both spatialindex and tools libraries from:

Rtree version 0.3 depends upon spatialindex version 1.1.1. Each library is a GNU-style build, so it should just be a matter of:

$ CPPFLAGS=-DNDEBUG ./configure; make; make install

for each. Debugging is on by default in 1.1.1, you’ll want to turn it off for use in production. The spatialindex library depends on the tools library, so make sure to build and install that first.

The command:

$ python install

installs an egg. You can build and test in place like so:

$ python test


See tests/R-Tree.txt.


See the tests/ file for a comparison.


For current information about this project, see the wiki.

If you have questions, please consider joining our community list:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Rtree, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size Rtree-0.3.0-py2.4-linux-i686.egg (53.7 kB) File type Egg Python version 2.4 Upload date Hashes View
Filename, size Rtree-0.3.0-py2.5-macosx-10.5-i386.egg (16.7 kB) File type Egg Python version 2.5 Upload date Hashes View
Filename, size Rtree-0.3.0.tar.gz (29.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page