ST_Transform

更新时间:
复制 MD 格式

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

ParameterDescription
g1 / geomThe geometry object to transform.
srid / toSridThe SRID of the target spatial reference system. The SRID must exist in the space_ref_sys table.
toProjA PROJ string defining the target spatial reference system.
fromProjA 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)