ST_Transform converts a geometry object from one spatial reference system to another, updating both the coordinates and the spatial reference system identifier (SRID).
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 SRID must exist in the space_ref_sys table. |
toProj | The PROJ string that defines the target spatial reference system. |
fromProj | The PROJ string that defines the source spatial reference system. Use this parameter when the input geometry has no SRID set. |
Usage notes
ST_Transformsupports circular strings, curves, and polyhedral surfaces.If the input geometry has no SRID, specify
fromProjto define the source spatial reference system.The SRID passed to
sridortoSridmust exist in thespace_ref_systable.
Examples
Transform using a target SRID
Convert a LINESTRING from WGS 84 geographic coordinates (EPSG:4326) to Web Mercator (EPSG:3857):
SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('LINESTRING(2 1,1 1)',4326),3857));
st_asewkt
---------------------------------------------------------------
SRID=3857;LINESTRING(222638.981586547 111325.142866385,111319.
..490793274 111325.142866385)
(1 row)