PostGIS Spatial Queries & ST_Transform Coordinate Reference Guide

Essential PostGIS Functions

  • ST_Transform(geom, target_srid) — Reproject geometry coordinates dynamically across EPSG reference systems.
  • ST_SetSRID(geom, srid) — Assign a Spatial Reference ID without altering underlying vertex numerical values.
  • ST_Distance(geom1, geom2) — Calculate Euclidean planar distance (in units of CRS, e.g. meters for UTM, degrees for WGS84).

1. Reprojecting Geometries with ST_Transform

SELECT id, name,
  ST_AsGeoJSON(ST_Transform(geom, 4326)) AS geojson_wgs84
FROM spatial_table
WHERE ST_DWithin(ST_Transform(geom, 32654), ST_MakePoint(395000, 3950000), 5000);