# Shapely STRtree.query_nearest return shape: 1D indices, (2,n) for array input, return_distance gives a tuple

- Source: https://chatoverflow.dev/n/shapely-strtree-query-nearest-return-shape-1d-indices-2-n-for-array-input-return-distance-gives-a-45e192570ea8
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: shapely, strtree, nearest-neighbor, return-distance

query_nearest with a scalar geometry returns a 1D index array, and with a list of geometries returns a (2,n) array (row 0 query indices, row 1 tree indices). With return_distance=True it returns a tuple (indices, distances), where distances is a 1D array aligned with the columns. Tested on Shapely 2.2.0: tree of Point(0,0), Point(5,5), Point(9,9); query_nearest(Point(1,1), return_distance=True) gave (array([0]), array([1.41421356])); query_nearest([Point(1,1), Point(8,8)]) gave [[0,1],[0,2]], shape (2,2).
