MySQL tutorial: ST_TRANSFORM [EN]
top of page
CerebroSQL

MySQL: 

ST_TRANSFORM

ST_Transform(g, target_srid)

Transforms a geometry from one spatial reference system (SRS) to
another. The return value is a geometry of the same type as the input
geometry with all coordinates transformed to the target SRID,
target_srid. Transformation support is limited to geographic SRSs,
unless the SRID of the geometry argument is the same as the target SRID
value, in which case the return value is the input geometry for any
valid SRS.

ST_Transform() handles its arguments as described in the introduction
to this section, with these exceptions:

o Geometry arguments that have an SRID value for a geographic SRS do
not produce an error.

o If the geometry or target SRID argument has an SRID value that refers
to an undefined spatial reference system (SRS), an ER_SRS_NOT_FOUND
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_srs_not_found) error occurs.

o If the geometry is in an SRS that ST_Transform() cannot transform
from, an ER_TRANSFORM_SOURCE_SRS_NOT_SUPPORTED
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_transform_source_srs_not_supported) error occurs.

o If the target SRID is in an SRS that ST_Transform() cannot transform
to, an ER_TRANSFORM_TARGET_SRS_NOT_SUPPORTED
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_transform_target_srs_not_supported) error occurs.

o If the geometry is in an SRS that is not WGS 84 and has no TOWGS84
clause, an ER_TRANSFORM_SOURCE_SRS_MISSING_TOWGS84
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_transform_source_srs_missing_towgs84) error occurs.

o If the target SRID is in an SRS that is not WGS 84 and has no TOWGS84
clause, an ER_TRANSFORM_TARGET_SRS_MISSING_TOWGS84
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_transform_target_srs_missing_towgs84) error occurs.

ST_SRID(g, target_srid) and ST_Transform(g, target_srid) differ as
follows:

o ST_SRID() changes the geometry SRID value without transforming its
coordinates.

o ST_Transform() transforms the geometry coordinates in addition to
changing its SRID value.

URL: https://dev.mysql.com/doc/refman/8.0/en/spatial-operator-functions.html

Example

mysql> SET @p = ST_GeomFromText('POINT(52.381389 13.064444)', 4326);
mysql> SELECT ST_AsText(@p);
+----------------------------+
| ST_AsText(@p) |
+----------------------------+
| POINT(52.381389 13.064444) |
+----------------------------+
mysql> SET @p = ST_Transform(@p, 4230);
mysql> SELECT ST_AsText(@p);
+---------------------------------------------+
| ST_AsText(@p) |
+---------------------------------------------+
| POINT(52.38208611407426 13.065520672345304) |
+---------------------------------------------+

bottom of page