Rechercher dans le manuel MySQL
12.16.11 Spatial GeoJSON Functions
This section describes functions for converting between GeoJSON documents and spatial values. GeoJSON is an open standard for encoding geometric/geographical features. For more information, see http://geojson.org. The functions discussed here follow GeoJSON specification revision 1.0.
GeoJSON supports the same geometric/geographic data types that MySQL supports. Feature and FeatureCollection objects are not supported, except that geometry objects are extracted from them. CRS support is limited to values that identify an SRID.
MySQL also supports a native JSON
data type and a set of SQL functions to enable operations on JSON
values. For more information, see Section 11.6, “The JSON Data Type”, and
Section 12.17, “JSON Functions”.
ST_AsGeoJSON(
g
[,max_dec_digits
[,options
]])Generates a GeoJSON object from the geometry
g
. The object string has the connection character set and collation.If any argument is
NULL
, the return value isNULL
. If any non-NULL
argument is invalid, an error occurs.max_dec_digits
, if specified, limits the number of decimal digits for coordinates and causes rounding of output. If not specified, this argument defaults to its maximum value of 232 − 1. The minimum is 0.options
, if specified, is a bitmask. The following table shows the permitted flag values. If the geometry argument has an SRID of 0, no CRS object is produced even for those flag values that request one.Flag Value Meaning 0 No options. This is the default if options
is not specified.1 Add a bounding box to the output. 2 Add a short-format CRS URN to the output. The default format is a short format ( EPSG:
).srid
4 Add a long-format CRS URN ( urn:ogc:def:crs:EPSG::
). This flag overrides flag 2. For example, option values of 5 and 7 mean the same (add a bounding box and a long-format CRS URN).srid
- +-------------------------------------------------------------+
- | ST_AsGeoJSON(ST_GeomFromText('POINT(11.11111 12.22222)'),2) |
- +-------------------------------------------------------------+
- | {"type": "Point", "coordinates": [11.11, 12.22]} |
- +-------------------------------------------------------------+
ST_GeomFromGeoJSON(
str
[,options
[,srid
]])Parses a string
str
representing a GeoJSON object and returns a geometry.If any argument is
NULL
, the return value isNULL
. If any non-NULL
argument is invalid, an error occurs.options
, if given, describes how to handle GeoJSON documents that contain geometries with coordinate dimensions higher than 2. The following table shows the permittedoptions
values.Option Value Meaning 1 Reject the document and produce an error. This is the default if options
is not specified.2, 3, 4 Accept the document and strip off the coordinates for higher coordinate dimensions. options
values of 2, 3, and 4 currently produce the same effect. If geometries with coordinate dimensions higher than 2 are supported in the future, these values will produce different effects.The
srid
argument, if given, must be a 32-bit unsigned integer. If not given, the geometry return value has an SRID of 4326.If
srid
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:
If a longitude value is not in the range (−180, 180], an
ER_LONGITUDE_OUT_OF_RANGE
error occurs.If a latitude value is not in the range [−90, 90], an
ER_LATITUDE_OUT_OF_RANGE
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.
GeoJSON geometry, feature, and feature collection objects may have a
crs
property. The parsing function parses named CRS URNs in theurn:ogc:def:crs:EPSG::
andsrid
EPSG:
namespaces, but not CRSs given as link objects. Also,srid
urn:ogc:def:crs:OGC:1.3:CRS84
is recognized as SRID 4326. If an object has a CRS that is not understood, an error occurs, with the exception that if the optionalsrid
argument is given, any CRS is ignored even if it is invalid.If a
crs
member that specifies an SRID different from the top-level object SRID is found at a lower level of the GeoJSON document, anER_INVALID_GEOJSON_CRS_NOT_TOP_LEVEL
error occurs.As specified in the GeoJSON specification, parsing is case sensitive for the
type
member of the GeoJSON input (Point
,LineString
, and so forth). The specification is silent regarding case sensitivity for other parsing, which in MySQL is not case-sensitive.This example shows the parsing result for a simple GeoJSON object:
- +--------------------------------------+
- | ST_AsText(ST_GeomFromGeoJSON(@json)) |
- +--------------------------------------+
- +--------------------------------------+
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-spatial-geojson-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
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.