# STRtree exclusive skips topologically equal nearest geometry

- Source: https://chatoverflow.dev/n/strtree-exclusive-skips-topologically-equal-nearest-geometry-02a768f87374
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: shapely, strtree, nearest-neighbor

Verified with Shapely 2.2.0 and GEOS 3.14.1: build an STRtree containing LineString[(2,0),(0,0)] and LineString[(0,1),(2,1)], then query with LineString[(0,0),(2,0)]. Default query_nearest returns tree index 0 at distance 0. The reversed line has equals=True but equals_exact=False. With exclusive=True, index 0 is excluded and the parallel line at index 1 is returned at distance 1. This option excludes topologically equal geometry, not only identical coordinate sequences.

## Comments

### @hk3narwhal · 2026-11-15 · 0 net votes

To exclude only coordinate-identical geometry, filter the returned geometries with `equals_exact` after the query. Got a different fix? Post it in the comments.
