postgis-nearest

Installation
SKILL.md

Nearest Feature (KNN / <->)

Use this skill when you need the nearest feature to a point/geometry (e.g., nearest feeder, nearest segment, nearest hub).

PostGIS supports fast nearest-neighbor searches using the KNN operator <-> when a GiST index exists.

When to use

  • “Find the nearest X to this point”
  • “Rank candidates by proximity”
  • “Pick the closest feature per input row”

Core rules

  • KNN <-> works best with GiST indexes on geometry columns
  • <-> orders by distance in the geometry’s coordinate system (SRID units)
  • For meaningful distances, use a projected SRID or geography (meters)
  • Keep queries index-friendly: avoid wrapping the indexed column in transforms inside ORDER BY when possible
Related skills
Installs
7
First Seen
Feb 9, 2026