MCPcopy Create free account
hub / github.com/shapely/shapely / query

Method query

shapely/strtree.py:109–274  ·  view source on GitHub ↗

Get the index combinations of all possibly intersecting geometries. Returns 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. If the input

(self, geometry, predicate=None, distance=None)

Source from the content-addressed store, hash-verified

107 return self._geometries
108
109 def query(self, geometry, predicate=None, distance=None):
110 """Get the index combinations of all possibly intersecting geometries.
111
112 Returns the integer indices of all combinations of each input geometry
113 and tree geometries where the bounding box of each input geometry
114 intersects the bounding box of a tree geometry.
115
116 If the input geometry is a scalar, this returns an array of shape (n, ) with
117 the indices of the matching tree geometries. If the input geometry is an
118 array_like, this returns an array with shape (2,n) where the subarrays
119 correspond to the indices of the input geometries and indices of the
120 tree geometries associated with each. To generate an array of pairs of
121 input geometry index and tree geometry index, simply transpose the
122 result.
123
124 If a predicate is provided, the tree geometries are first queried based
125 on the bounding box of the input geometry and then are further filtered
126 to those that meet the predicate when comparing the input geometry to
127 the tree geometry:
128 predicate(geometry, tree_geometry)
129
130 The 'dwithin' predicate requires GEOS >= 3.10.
131
132 Bounding boxes are limited to two dimensions and are axis-aligned
133 (equivalent to the ``bounds`` property of a geometry); any Z values
134 present in input geometries are ignored when querying the tree.
135
136 Any input geometry that is None or empty will never match geometries in
137 the tree.
138
139 Parameters
140 ----------
141 geometry : Geometry or array_like
142 Input geometries to query the tree and filter results using the
143 optional predicate.
144 predicate : {None, 'intersects', 'within', 'contains', 'overlaps', 'crosses',\
145'touches', 'covers', 'covered_by', 'contains_properly', 'dwithin'}, optional
146 The predicate to use for testing geometries from the tree
147 that are within the input geometry's bounding box.
148 distance : number or array_like, optional
149 Distances around each input geometry within which to query the tree
150 for the 'dwithin' predicate. If array_like, shape must be
151 broadcastable to shape of geometry. Required if predicate='dwithin'.
152
153 Returns
154 -------
155 ndarray with shape (n,) if geometry is a scalar
156 Contains tree geometry indices.
157
158 OR
159
160 ndarray with shape (2, n) if geometry is an array_like
161 The first subarray contains input geometry indices.
162 The second subarray contains tree geometry indices.
163
164 Examples
165 --------
166 >>> from shapely import box, Point, STRtree

Callers 15

test_initFunction · 0.95
test_referencesFunction · 0.95
test_flush_geometriesFunction · 0.95
time_tree_createMethod · 0.95
test_query_pointsFunction · 0.80
test_query_linesFunction · 0.80
test_query_polygonsFunction · 0.80

Calls 3

dwithinMethod · 0.80
get_valueMethod · 0.80

Tested by 15

test_initFunction · 0.76
test_referencesFunction · 0.76
test_flush_geometriesFunction · 0.76
test_query_pointsFunction · 0.64
test_query_linesFunction · 0.64
test_query_polygonsFunction · 0.64