Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 32.3Mb
PDF (A4) - 32.3Mb
PDF (RPM) - 30.4Mb
HTML Download (TGZ) - 7.8Mb
HTML Download (Zip) - 7.8Mb
HTML Download (RPM) - 6.7Mb
Man Pages (TGZ) - 142.5Kb
Man Pages (Zip) - 201.7Kb
Info (Gzip) - 3.0Mb
Info (Zip) - 3.0Mb


MySQL 8.0 Reference Manual  /  ...  /  Functions That Create Geometry Values from WKT Values

Pre-General Availability Draft: 2017-05-26

13.15.3 Functions That Create Geometry Values from WKT Values

These functions take as arguments a Well-Known Text (WKT) representation and, optionally, a spatial reference system identifier (SRID). They return the corresponding geometry.

The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

ST_GeomFromText() accepts a WKT value of any geometry type as its first argument. Other functions provide type-specific construction functions for construction of geometry values of each geometry type.

Functions such as ST_GeomFromText() that accept WKT geometry collection arguments understand both OpenGIS 'GEOMETRYCOLLECTION EMPTY' standard syntax and MySQL 'GEOMETRYCOLLECTION()' nonstandard syntax. Functions such as ST_AsWKT() that produce WKT values produce 'GEOMETRYCOLLECTION EMPTY' standard syntax:

mysql> SET @s1 = ST_GeomFromText('GEOMETRYCOLLECTION()');
mysql> SET @s2 = ST_GeomFromText('GEOMETRYCOLLECTION EMPTY');
mysql> SELECT ST_AsWKT(@s1), ST_AsWKT(@s2);
+--------------------------+--------------------------+
| ST_AsWKT(@s1)            | ST_AsWKT(@s2)            |
+--------------------------+--------------------------+
| GEOMETRYCOLLECTION EMPTY | GEOMETRYCOLLECTION EMPTY |
+--------------------------+--------------------------+

For a description of WKT format, see Well-Known Text (WKT) Format.

  • ST_GeomCollFromText(wkt[, srid [, options]]), ST_GeometryCollectionFromText(wkt[, srid [, options]]), ST_GeomCollFromTxt(wkt[, srid [, options]])

    Constructs a GeometryCollection value using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.

    mysql> SET @g = "MULTILINESTRING((10 10, 11 11), (9 9, 10 10))";
    mysql> SELECT ST_AsText(ST_GeomCollFromText(@g));
    +--------------------------------------------+
    | ST_AsText(ST_GeomCollFromText(@g))         |
    +--------------------------------------------+
    | MULTILINESTRING((10 10,11 11),(9 9,10 10)) |
    +--------------------------------------------+
    
  • ST_GeomFromText(wkt[, srid [, options]]), ST_GeometryFromText(wkt[, srid [, options]])

    Constructs a geometry value of any type using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.

  • ST_LineFromText(wkt[, srid [, options]]), ST_LineStringFromText(wkt[, srid [, options]])

    Constructs a LineString value using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.

  • ST_MLineFromText(wkt[, srid [, options]]), ST_MultiLineStringFromText(wkt[, srid [, options]])

    Constructs a MultiLineString value using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.

  • ST_MPointFromText(wkt[, srid [, options]]), ST_MultiPointFromText(wkt[, srid [, options]])

    Constructs a MultiPoint value using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.

    In MySQL 8.0, spatial functions such as ST_MPointFromText() and ST_GeomFromText() that accept WKT-format representations of MultiPoint values permit individual points within values to be surrounded by parentheses. For example, both of the following function calls are valid:

    ST_MPointFromText('MULTIPOINT (1 1, 2 2, 3 3)')
    ST_MPointFromText('MULTIPOINT ((1 1), (2 2), (3 3))')
    
  • ST_MPolyFromText(wkt[, srid [, options]]), ST_MultiPolygonFromText(wkt[, srid [, options]])

    Constructs a MultiPolygon value using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.

  • ST_PointFromText(wkt[, srid [, options]])

    Constructs a Point value using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.

  • ST_PolyFromText(wkt[, srid [, options]]), ST_PolygonFromText(wkt[, srid [, options]])

    Constructs a Polygon value using its WKT representation and SRID.

    The result is NULL if the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL.

    The functions interpret geographic coordinates (latitude, longitude) as in the order specified by the spatial reference system. An optional options argument may be given to override the default axis order.

    The result is NULL if the options argument is NULL. If the options argument is invalid, an error occurs to indicate why.


User Comments
Sign Up Login You must be logged in to post a comment.