Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 35.5Mb
PDF (A4) - 35.5Mb
PDF (RPM) - 34.6Mb
EPUB - 8.7Mb
HTML Download (TGZ) - 8.5Mb
HTML Download (Zip) - 8.5Mb
HTML Download (RPM) - 7.3Mb
Eclipse Doc Plugin (TGZ) - 9.3Mb
Eclipse Doc Plugin (Zip) - 11.5Mb
Man Pages (TGZ) - 201.5Kb
Man Pages (Zip) - 306.8Kb
Info (Gzip) - 3.3Mb
Info (Zip) - 3.3Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  Geometry Format Conversion Functions

13.15.6 Geometry Format Conversion Functions

MySQL supports the functions listed in this section for converting geometry values from internal geometry format to WKT or WKB format.

In addition, there are functions to convert a string from WKT or WKB format to internal geometry format. See Section 13.15.3, “Functions That Create Geometry Values from WKT Values”, and Section 13.15.4, “Functions That Create Geometry Values from WKB Values”.

  • AsBinary(g), AsWKB(g)

    ST_AsBinary(), ST_AsWKB(), AsBinary(), and AsWKB() are synonyms. For more information, see the description of ST_AsBinary().

    AsBinary() and AsWKB() are deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. Use ST_AsBinary() and ST_AsWKB() instead.

  • AsText(g), AsWKT(g)

    ST_AsText(), ST_AsWKT(), AsText(), and AsWKT() are synonyms. For more information, see the description of ST_AsText().

    AsText() and AsWKT() are deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. Use ST_AsText() and ST_AsWKT() instead.

  • ST_AsBinary(g), ST_AsWKB(g)

    Converts a value in internal geometry format to its WKB representation and returns the binary result.

    SELECT ST_AsBinary(g) FROM geom;
    

    ST_AsBinary(), ST_AsWKB(), AsBinary(), and AsWKB() are synonyms.

  • ST_AsText(g), ST_AsWKT(g)

    Converts a value in internal geometry format to its WKT representation and returns the string result.

    mysql> SET @g = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT ST_AsText(ST_GeomFromText(@g));
    +--------------------------------+
    | ST_AsText(ST_GeomFromText(@g)) |
    +--------------------------------+
    | LINESTRING(1 1,2 2,3 3)        |
    +--------------------------------+
    

    ST_AsText(), ST_AsWKT(), AsText(), and AsWKT() are synonyms.

    As of MySQL 5.7.9, output for MultiPoint values includes parentheses around each point. For example:

    mysql> SET @mp = 'MULTIPOINT(1 1, 2 2, 3 3)';
    mysql> SELECT ST_AsText(ST_GeomFromText(@mp));
    +---------------------------------+
    | ST_AsText(ST_GeomFromText(@mp)) |
    +---------------------------------+
    | MULTIPOINT((1 1),(2 2),(3 3))   |
    +---------------------------------+
    

    Before MySQL 5.7.9, output for the same value does not include parentheses around each point:

    mysql> SET @mp = 'MULTIPOINT(1 1, 2 2, 3 3)';
    mysql> SELECT ST_AsText(ST_GeomFromText(@mp));
    +---------------------------------+
    | ST_AsText(ST_GeomFromText(@mp)) |
    +---------------------------------+
    | MULTIPOINT(1 1,2 2,3 3)         |
    +---------------------------------+
    

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