All Products
Search
Document Center

PolarDB:ST_Transform

Last Updated:Mar 28, 2026

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

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