Rechercher dans le manuel MySQL

12.16.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, or for swapping the order of X and Y coordinates.

There are also functions to convert a string from WKT or WKB format to internal geometry format. See Section 12.16.3, “Functions That Create Geometry Values from WKT Values”, and Section 12.16.4, “Functions That Create Geometry Values from WKB Values”.

Functions such as ST_GeomFromText() that accept WKT geometry collection arguments understand both OpenGIS 'GEOMETRYCOLLECTION EMPTY' standard syntax and MySQL 'GEOMETRYCOLLECTION()' nonstandard syntax. Another way to produce an empty geometry collection is by calling GeometryCollection() with no arguments. Functions such as ST_AsWKT() that produce WKT values produce 'GEOMETRYCOLLECTION EMPTY' standard syntax:

  1. mysql> SET @s1 = ST_GeomFromText('GEOMETRYCOLLECTION()');
  2. mysql> SET @s2 = ST_GeomFromText('GEOMETRYCOLLECTION EMPTY');
  3. mysql> SELECT ST_AsWKT(@s1), ST_AsWKT(@s2);
  4. +--------------------------+--------------------------+
  5. | ST_AsWKT(@s1)            | ST_AsWKT(@s2)            |
  6. +--------------------------+--------------------------+
  7. +--------------------------+--------------------------+
  8. mysql> SELECT ST_AsWKT(GeomCollection());
  9. +----------------------------+
  10. | ST_AsWKT(GeomCollection()) |
  11. +----------------------------+
  12. | GEOMETRYCOLLECTION EMPTY   |
  13. +----------------------------+

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

  • If any argument is NULL, the return value is NULL.

  • If any geometry argument is not a syntactically well-formed geometry, an ER_GIS_INVALID_DATA error occurs.

  • If any geometry argument is in an undefined spatial reference system, the axes are output in the order they appear in the geometry and an ER_WARN_SRS_NOT_FOUND_AXIS_ORDER warning occurs.

  • By default, geographic coordinates (latitude, longitude) are interpreted as in the order specified by the spatial reference system of geometry arguments. An optional options argument may be given to override the default axis order. options consists of a list of comma-separated key=value. The onlypermitted key value is axis-order, with permitted values of lat-long, long-lat and srid-defined (the default).

    If the options argument is NULL, the return value is NULL. If the options argument is invalid, an error occurs to indicate why.

  • Otherwise, the return value is non-NULL.

These functions are available for format conversions or coordinate swapping:

  • ST_AsBinary(g [, options]), ST_AsWKB(g [, options])

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

    The function return value has geographic coordinates (latitude, longitude) in the order specified by the spatial reference system that applies to the geometry argument. An optional options argument may be given to override the default axis order.

    ST_AsBinary() and ST_AsWKB() handle their arguments as described in the introduction to this section.

    1. mysql> SET @g = ST_LineFromText('LINESTRING(0 5,5 10,10 15)', 4326);
    2. mysql> SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g)));
    3. +-----------------------------------------+
    4. | ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g))) |
    5. +-----------------------------------------+
    6. | LINESTRING(5 0,10 5,15 10)              |
    7. +-----------------------------------------+
    8. mysql> SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=long-lat')));
    9. +----------------------------------------------------------------+
    10. | ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=long-lat'))) |
    11. +----------------------------------------------------------------+
    12. | LINESTRING(0 5,5 10,10 15)                                     |
    13. +----------------------------------------------------------------+
    14. mysql> SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=lat-long')));
    15. +----------------------------------------------------------------+
    16. | ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=lat-long'))) |
    17. +----------------------------------------------------------------+
    18. | LINESTRING(5 0,10 5,15 10)                                     |
    19. +----------------------------------------------------------------+
  • ST_AsText(g [, options]), ST_AsWKT(g [, options])

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

    The function return value has geographic coordinates (latitude, longitude) in the order specified by the spatial reference system that applies to the geometry argument. An optional options argument may be given to override the default axis order.

    ST_AsText() and ST_AsWKT() handle their arguments as described in the introduction to this section.

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

    Output for MultiPoint values includes parentheses around each point. For example:

    1. mysql> SELECT ST_AsText(ST_GeomFromText(@mp));
    2. +---------------------------------+
    3. | ST_AsText(ST_GeomFromText(@mp)) |
    4. +---------------------------------+
    5. | MULTIPOINT((1 1),(2 2),(3 3))   |
    6. +---------------------------------+
  • ST_SwapXY(g)

    Accepts an argument in internal geometry format, swaps the X and Y values of each coordinate pair within the geometry, and returns the result.

    ST_SwapXY() handles its arguments as described in the introduction to this section.

    1. mysql> SET @g = ST_LineFromText('LINESTRING(0 5,5 10,10 15)');
    2. mysql> SELECT ST_AsText(@g);
    3. +----------------------------+
    4. | ST_AsText(@g)              |
    5. +----------------------------+
    6. | LINESTRING(0 5,5 10,10 15) |
    7. +----------------------------+
    8. mysql> SELECT ST_AsText(ST_SwapXY(@g));
    9. +----------------------------+
    10. | ST_AsText(ST_SwapXY(@g))   |
    11. +----------------------------+
    12. | LINESTRING(5 0,10 5,15 10) |
    13. +----------------------------+

Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-gis-format-conversion-functions.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut