Documentation Home
MySQL 9.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.0Mb
PDF (A4) - 40.1Mb
Man Pages (TGZ) - 259.0Kb
Man Pages (Zip) - 366.2Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


MySQL 9.0 Reference Manual  / ...  / Functions and Operators  / Spatial Analysis Functions  /  Functions That Create Geometry Values from WKT Values

14.16.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. For a description of WKT format, seeWell-Known Text (WKT) Format.

Functions in this section detect arguments in either Cartesian or geographic spatial reference systems (SRSs), and return results appropriate to the SRS.

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 asST_MPointFromText() andST_GeomFromText() that accept WKT-format representations ofMultiPoint 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))')

Functions such asST_GeomFromText() that accept WKT geometry collection arguments understand both OpenGIS'GEOMETRYCOLLECTION EMPTY' standard syntax and MySQL'GEOMETRYCOLLECTION()' nonstandard syntax. Functions such asST_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 |+--------------------------+--------------------------+

Unless otherwise specified, functions in this section handle their geometry arguments as follows:

  • If any geometry argument isNULL or is not a syntactically well-formed geometry, or if the SRID argument isNULL, the return value isNULL.

  • By default, geographic coordinates (latitude, longitude) are interpreted as in the order specified by the spatial reference system of geometry arguments. An optionaloptions argument may be given to override the default axis order.options consists of a list of comma-separatedkey=value. The only permittedkey value isaxis-order, with permitted values oflat-long,long-lat andsrid-defined (the default).

    If theoptions argument isNULL, the return value isNULL. If theoptions argument is invalid, an error occurs to indicate why.

  • If an SRID argument refers to an undefined spatial reference system (SRS), anER_SRS_NOT_FOUND error occurs.

  • For geographic SRS geometry arguments, if any argument has a longitude or latitude that is out of range, an error occurs:

    Ranges shown are in degrees. If an SRS uses another unit, the range uses the corresponding values in its unit. The exact range limits deviate slightly due to floating-point arithmetic.

These functions are available for creating geometries from WKT values: