Converts a geometry object from one spatial reference system (SRS) to another, recalculating its coordinates in the target system.
Syntax
geometry ST_Transform(geometry g1, integer srid);
geometry ST_Transform(geometry geom, text toProj);
geometry ST_Transform(geometry geom, text fromProj, text toProj);
geometry ST_Transform(geometry geom, text fromProj, integer toSrid);Parameters
| Parameter | Description |
|---|---|
g1 / geom | The geometry object to transform. |
srid / toSrid | The SRID of the target spatial reference system. The specified SRID must exist in the space_ref_sys table. |
toProj | A PROJ string that defines the target spatial reference system. |
fromProj | A PROJ string that defines the source spatial reference system. |
Description
ST_Transform supports circular strings, curves, and polyhedral surfaces.
Examples
Convert coordinates from WGS 84 to Web Mercator
This is the most common transformation in web mapping: from geographic coordinates (EPSG:4326) to the Web Mercator projection (EPSG:3857).
SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('LINESTRING(2 1,1 1)', 4326), 3857));Expected output:
st_asewkt
---------------------------------------------------------------
SRID=3857;LINESTRING(222638.981586547 111325.142866385,111319.
..490793274 111325.142866385)
(1 row)