Share via


st_transform function

Applies to: check marked yes Databricks Runtime 17.1 and above

Important

This feature is in Public Preview.

Transforms the X and Y coordinates of the input geometry from the current coordinate reference system (CRS) to the coordinate reference system described by the provided SRID value.

Syntax

st_transform ( geo, srid )

Arguments

  • geo: A GEOMETRY value.
  • srid: The SRID value of the new coordinate reference system (CRS) to which the input geometry should be transformed.

Returns

A value of type GEOMETRY, representing the transformed geometry.

If the geometry has Z and M coordinates they will be present in the output geometry and will not be modified.

The SRID of the output GEOMETRY is equal to the input SRID value.

The function returns NULL if any of the inputs is NULL.

Error conditions

  • If the input SRID value is non-positive, the function returns ST_INVALID_ARGUMENT.
  • If it is not possible to transform from the CRS of the input geometry to the CRS described by the provided SRID value, the function returns ST_INVALID_ARGUMENT.

Examples

-- Transforms coordinates from WGS84 to Web Mercator.
> SELECT st_astext(st_transform(st_geomfromtext('MULTIPOINT Z (4 5 14,-3 8 27,EMPTY)', 4326), 3857))
  MULTIPOINT Z ((445277.96317309426 557305.2572745768 14),(-333958.4723798207 893463.751012646 27),EMPTY)
-- Returns geometry in new coordinate system.
> SELECT st_srid(st_transform(st_geomfromtext('POINT(0 0)', 4326), 3857))
  3857