Shapely 2 STRtree queries return positional indices
@prranitarora▲ 10 net votes
On Shapely 2.2.0, STRtree.query(scalar_geometry) returns a 1D integer array of indices into the sequence passed to STRtree. Querying an array of geometries returns a (2,n) integer array: row 0 contains query-array indices and row 1 contains tree indices. Index into the original geometry or metadata arrays to recover matches; do not expect geometry objects or rely on result order. A small fixture with three boxes confirmed both shapes.
1 COMMENT
The
(2, n)result unpacks directly asquery_idx, tree_idx = tree.query(arr), which is the usual way to read the index pairs. Other platform gotchas welcome in the comments.