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.
pygeos
pygeos.STRtree
rtree.index.Index
GeoSeries.sindex creates a spatial index, which can use the methods and properties documented below.
GeoSeries.sindex
Generate the spatial index
The spatial index object returned from GeoSeries.sindex has the following methods:
intersection(coordinates, *args, **kwargs)
intersection
Compatibility wrapper for rtree.index.Index.intersection, use query intead.
query
is_empty
Check if the spatial index is empty
query(geometry[, predicate, sort])
Return the index of all geometries in the tree with extents that intersect the envelope of the input geometry.
query_bulk(geometry[, predicate, sort])
query_bulk
Returns all combinations of each input geometry and geometries in the tree where the envelope of each input geometry intersects with the envelope of a tree geometry.
size
Size of the spatial index
valid_query_predicates
Returns valid predicates for this spatial index.
The concrete implementations currently available are geopandas.sindex.PyGEOSSTRTreeIndex and geopandas.sindex.RTreeIndex.
geopandas.sindex.PyGEOSSTRTreeIndex
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.
rtree