geopandas.GeoSeries.sindex#
- property GeoSeries.sindex[source]#
Generate the spatial index
Creates R-tree spatial index based on
shapely.STRtree
.Note that the spatial index may not be fully initialized until the first use.
Examples
>>> from shapely.geometry import box >>> s = geopandas.GeoSeries(geopandas.points_from_xy(range(5), range(5))) >>> s 0 POINT (0 0) 1 POINT (1 1) 2 POINT (2 2) 3 POINT (3 3) 4 POINT (4 4) dtype: geometry
Query the spatial index with a single geometry based on the bounding box:
>>> s.sindex.query(box(1, 1, 3, 3)) array([1, 2, 3])
Query the spatial index with a single geometry based on the predicate:
>>> s.sindex.query(box(1, 1, 3, 3), predicate="contains") array([2])
Query the spatial index with an array of geometries based on the bounding box:
>>> s2 = geopandas.GeoSeries([box(1, 1, 3, 3), box(4, 4, 5, 5)]) >>> s2 0 POLYGON ((3 1, 3 3, 1 3, 1 1, 3 1)) 1 POLYGON ((5 4, 5 5, 4 5, 4 4, 5 4)) dtype: geometry
>>> s.sindex.query(s2) array([[0, 0, 0, 1], [1, 2, 3, 4]])
Query the spatial index with an array of geometries based on the predicate:
>>> s.sindex.query(s2, predicate="contains") array([[0], [2]])