ST_Transform reprojects a geometry from one spatial reference system to another.
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 | A PROJ string defining the target spatial reference system. |
fromProj | A PROJ string defining the source spatial reference system. |
Description
ST_Transform supports circular strings, curves, and polyhedral surfaces.
Example
Convert a line from WGS 84 (EPSG:4326) to Web Mercator (EPSG:3857):
SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('LINESTRING(2 1,1 1)',4326),3857));Output:
st_asewkt
---------------------------------------------------------------------------------------------------
SRID=3857;LINESTRING(222638.98158654713 111325.14286638486,111319.49079327357 111325.14286638486)
(1 row)该文章对您有帮助吗?