postgis-distance
ST_Distance (Numeric Distance)
Use this skill when you need the numeric distance value between geometries (for reporting, ranking display, metadata).
If you need a boolean “within X distance” filter, prefer ST_DWithin (faster). A common pattern is:
- use
ST_DWithinto filter candidates - use
ST_Distanceto compute the returned distance value
Core rules
- Units depend on type:
geometry→ SRID units (degrees/meters/feet depending on SRID)geography→ meters
- Geometries must be in the same SRID for geometry math
- Do not compute meaningful distances in EPSG:4326 geometry (degrees) unless you intend degrees
Canonical patterns
More from mmbmf1/geospatial-skills
geojson-postgis
Serialize PostGIS geometry rows into a GeoJSON FeatureCollection for map display (4326, Feature + properties).
21geojson-points
Convert JSON rows with latitude/longitude fields into a GeoJSON FeatureCollection using raw PostGIS SQL.
16geojson-wkt
Convert JSON rows with WKT geometry strings into a GeoJSON FeatureCollection using raw PostGIS SQL.
13postgis-dwithin
Distance-based spatial filtering with ST_DWithin, using index-friendly and unit-safe patterns.
8postgis-nearest
Find nearest features efficiently using PostGIS KNN (<->) and distance ordering (with SRID/unit guidance).
7postgis-extract-xy
Extract longitude and latitude from PostGIS geometries using ST_X and ST_Y safely.
7