ST_Transform
What is ST_Transform?
ST_Transform returns a new geometry whose coordinates have been converted from the input SRID to the target SRID using PROJ. Both SRIDs must be defined in spatial_ref_sys.
1ST_Transform(geometry geom, integer to_srid) → geometry
2ST_Transform(geometry geom, text to_proj) → geometry
3ST_Transform(geometry geom, text from_proj, text to_proj) → geometry
4ST_Transform(geometry geom, text from_proj, integer to_srid) → geometryPROJ chooses an appropriate transformation pipeline; use ST_TransformPipeline for explicit control.
When would you use ST_Transform?
Use ST_Transform to move data between CRSs — reprojecting WGS84 (4326) inputs to Web Mercator (3857) for tile generation, or to a local UTM zone for accurate metric measurements. It is the everyday tool for cross-CRS spatial joins and for exporting data to systems expecting a specific CRS.
Reprojection is lossy in precision and can produce invalid geometry at extreme latitudes. Pair with ST_MakeValid when routing data through projections that distort heavily near poles.
FAQs
What if the input geometry has SRID = 0?
ST_Transform raises an error — the source CRS must be known. Tag the geometry with ST_SetSRID first, or use the four-argument overload that accepts an explicit from_proj string.
How do I reproject very long line segments accurately?
Densify with ST_Segmentize before transforming. Long segments reprojected end-to-end can deviate from the correct curved path.
How can I control which transformation pipeline PROJ uses?
Call ST_TransformPipeline with an explicit pipeline string. ST_Transform lets PROJ choose, which may vary across PROJ versions.
Is ST_Transform expensive on large tables?
Yes. Consider storing a pre-projected column if you frequently query in a specific CRS, or use generated columns to materialise the transform on write.