content_image/668592.jpg
## 12.17.11 Spatial GeoJSON Functions 

| POINT(45 -20) | +---------------------------------------+ 

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.5, “The JSON Data Type” , and Section 12.18, “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 is NULL . 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 2$^{32}$ − 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. 

<img src='content_image/668592.jpg'>

mysql> SELECT ST_AsGeoJSON(ST_GeomFromText(’POINT(11.11111 12.22222)’),2); +-------------------------------------------------------------+ | 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 is NULL . If any non- NULL  argument is invalid, an error occurs. 

