Spatial index#

GeoPandas offers built-in support for spatial indexing using an R-Tree algorithm. Depending on the ability to import PyGEOS, GeoPandas will either use pygeos.STRtree or rtree.index.Index. The main interface for both is the same and follows the PyGEOS model.

GeoSeries.sindex creates a spatial index, which can use the methods and properties documented below.



Generate the spatial index

Spatial index object#

The spatial index object returned from GeoSeries.sindex has the following methods:

intersection(coordinates, *args, **kwargs)

Compatibility wrapper for rtree.index.Index.intersection, use query instead.


Check if the spatial index is empty

nearest(*args, **kwargs)

Return the nearest geometry in the tree for each input geometry in geometry.

query(geometry[, predicate, sort])

Return the integer indices of all combinations of each input geometry and tree geometries where the bounding box of each input geometry intersects the bounding box of a tree geometry.


Size of the spatial index


Returns valid predicates for this spatial index.

The concrete implementations currently available are geopandas.sindex.PyGEOSSTRTreeIndex and geopandas.sindex.RTreeIndex.

In addition to the methods listed above, the rtree-based spatial index (geopandas.sindex.RTreeIndex) offers the full capability of rtree.index.Index - see the full API in the rtree documentation.

Similarly, the PyGEOS-based spatial index (geopandas.sindex.PyGEOSSTRTreeIndex) offers the full capability of pygeos.STRtree, including nearest-neighbor queries. See the full API in the PyGEOS STRTree documentation.