geopandas.sindex.SpatialIndex.query_bulk¶
- SpatialIndex.query_bulk(geometry, predicate=None, sort=False)¶
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.
In the context of a spatial join, input geometries are the “left” geometries that determine the order of the results, and tree geometries are “right” geometries that are joined against the left geometries. This effectively performs an inner join, where only those combinations of geometries that can be joined based on envelope overlap or optional predicate are returned.
When using the
rtree
package, this is not a vectorized function and may be slow. If speed is important, please use PyGEOS.- Parameters
- geometry{GeoSeries, GeometryArray, numpy.array of PyGEOS geometries}
Accepts GeoPandas geometry iterables (GeoSeries, GeometryArray) or a numpy array of PyGEOS geometries.
- predicate{None, ‘intersects’, ‘within’, ‘contains’, ‘overlaps’, ‘crosses’, ‘touches’}, optional
If predicate is provided, the input geometries are tested using the predicate function against each item in the tree whose extent intersects the envelope of the each input geometry: predicate(input_geometry, tree_geometry). If possible, prepared geometries are used to help speed up the predicate operation.
- sortbool, default False
If True, results sorted lexicographically using geometry’s indexes as the primary key and the sindex’s indexes as the secondary key. If False, no additional sorting is applied.
- Returns
- ndarray with shape (2, n)
The first subarray contains input geometry integer indexes. The second subarray contains tree geometry integer indexes.
Examples
>>> from shapely.geometry import Point, box >>> s = geopandas.GeoSeries(geopandas.points_from_xy(range(10), range(10))) >>> s 0 POINT (0.00000 0.00000) 1 POINT (1.00000 1.00000) 2 POINT (2.00000 2.00000) 3 POINT (3.00000 3.00000) 4 POINT (4.00000 4.00000) 5 POINT (5.00000 5.00000) 6 POINT (6.00000 6.00000) 7 POINT (7.00000 7.00000) 8 POINT (8.00000 8.00000) 9 POINT (9.00000 9.00000) dtype: geometry >>> s2 = geopandas.GeoSeries([box(2, 2, 4, 4), box(5, 5, 6, 6)]) >>> s2 0 POLYGON ((4.00000 2.00000, 4.00000 4.00000, 2.... 1 POLYGON ((6.00000 5.00000, 6.00000 6.00000, 5.... dtype: geometry
>>> s.sindex.query_bulk(s2) array([[0, 0, 0, 1, 1], [2, 3, 4, 5, 6]])
>>> s.sindex.query_bulk(s2, predicate="contains") array([[0], [3]])