This section describes functions for converting between GeoJSON documents and spatial values. 本节介绍用于在GeoJSON文档和空间值之间进行转换的函数。GeoJSON is an open standard for encoding geometric/geographical features. GeoJSON是编码几何/地理特征的开放标准。For more information, see http://geojson.org. 有关详细信息,请参阅http://geojson.org。The functions discussed here follow GeoJSON specification revision 1.0.这里讨论的函数遵循GeoJSON规范修订版1.0。
GeoJSON supports the same geometric/geographic data types that MySQL supports. GeoJSON支持MySQL支持的相同的几何/地理数据类型。Feature and FeatureCollection objects are not supported, except that geometry objects are extracted from them. 不支持Feature
和FeatureCollection
对象,除非从中提取几何体对象。CRS support is limited to values that identify an SRID.CRS支持仅限于标识SRID的值。
MySQL also supports a native MySQL还支持一个原生JSON
data type and a set of SQL functions to enable operations on JSON values. JSON
数据类型和一组SQL函数来支持对JSON值的操作。For more information, see Section 11.5, “The JSON Data Type”, and Section 12.18, “JSON Functions”.有关更多信息,请参阅第11.5节,“JSON数据类型”和第12.18节,“JSON函数”。
ST_AsGeoJSON(
g
[, max_dec_digits
[, options
]])
Generates a GeoJSON object from the geometry 从几何体g
. g
生成GeoJSON对象。The object string has the connection character set and collation.对象字符串具有连接字符集和排序规则。
If any argument is 如果任何参数为NULL
, the return value is NULL
. NULL
,则返回值为NULL
。If any non-如果任何非NULL
argument is invalid, an error occurs.NULL
参数无效,则会发生错误。
max_dec_digits
, if specified, limits the number of decimal digits for coordinates and causes rounding of output. max_dec_digits
(如果指定)限制坐标的小数位数,并导致输出舍入。If not specified, this argument defaults to its maximum value of 232 − 1. 如果未指定,则此参数默认为其最大值232-1。The minimum is 0.最小值为0。
options
, if specified, is a bitmask. options
(如果指定)是位掩码。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.如果geometry参数的SRID为0,则不会生成CRS对象,即使对于那些请求CRS对象的标志值也是如此。
0 | options is not specified.options ,则这是默认值。 |
1 | |
2 | EPSG: ).EPSG: )。 |
4 | urn:ogc:def:crs:EPSG:: ). urn:ogc:def:crs:EPSG:: )。 |
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 解析表示GeoJSON对象的字符串str
representing a GeoJSON object and returns a geometry.str
并返回几何体。
If any argument is 如果任何参数为NULL
, the return value is NULL
. NULL
,则返回值为NULL
。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. options
(如果给定)描述如何处理包含坐标维度大于2的几何体的GeoJSON文档。The following table shows the permitted 下表显示了允许的options
values.options
值。
1 | options is not specified.options ,则这是默认值。 |
2, 3, 4 |
options
values of 2, 3, and 4 currently produce the same effect. options
值2、3和4当前会产生相同的效果。If geometries with coordinate dimensions higher than 2 are supported in the future, you can expect these values to produce different effects.如果将来支持坐标标注大于2的几何图形,则可以预期这些值会产生不同的效果。
The srid
argument, if given, must be a 32-bit unsigned integer. srid
参数(如果给定)必须是32位无符号整数。If not given, the geometry return value has an SRID of 4326.如果未给定,则几何体返回值的SRID为4326。
If 如果srid
refers to an undefined spatial reference system (SRS), an ER_SRS_NOT_FOUND
error occurs.srid
引用未定义的空间参考系(SRS),则会发生ER_SRS_NOT_FOUND
错误。
For geographic SRS geometry arguments, if any argument has a longitude or latitude that is out of range, an error occurs:对于地理SRS几何参数,如果任何参数的经度或纬度超出范围,则会发生错误:
If a longitude value is not in the range (−180, 180], an 如果经度值不在范围(-180,180]内,则会发生ER_LONGITUDE_OUT_OF_RANGE
error occurs.ER_LONGITUDE_OUT_OF_RANGE
错误。
If a latitude value is not in the range [−90, 90], an 如果纬度值不在[-90,90]范围内,则会发生ER_LATITUDE_OUT_OF_RANGE
error occurs.ER_LATITUDE_OUT_OF_RANGE
错误。
Ranges shown are in degrees. 显示的范围以度为单位。If an SRS uses another unit, the range uses the corresponding values in its unit. 如果SRS使用另一个单位,则范围使用其单位中的相应值。The exact range limits deviate slightly due to floating-point arithmetic.由于采用浮点运算,精确的范围限制略有偏差。
GeoJSON geometry, feature, and feature collection objects may have a GeoJSON几何体、要素和要素集合对象可能具有crs
property. crs
属性。The parsing function parses named CRS URNs in the 解析函数解析urn:ogc:def:crs:EPSG::
and srid
EPSG:
namespaces, but not CRSs given as link objects. srid
urn:ogc:def:crs:EPSG::
和srid
EPSG:
命名空间中的命名CRS URNs,但不解析作为链接对象提供的CRS。srid
Also, 此外,urn:ogc:def:crs:OGC:1.3:CRS84
is recognized as SRID 4326. urn:ogc:def:crs:OGC:1.3:CRS84
被识别为SRID 4326。If an object has a CRS that is not understood, an error occurs, with the exception that if the optional 如果一个对象有一个不可理解的CRS,则会发生一个错误,除非给出了可选的srid
argument is given, any CRS is ignored even if it is invalid.srid
参数,否则任何CRS都会被忽略,即使它是无效的。
If a 如果在GeoJSON文档的较低级别找到指定与顶级对象SRID不同的SRID的crs成员,则会发生crs
member that specifies an SRID different from the top-level object SRID is found at a lower level of the GeoJSON document, an ER_INVALID_GEOJSON_CRS_NOT_TOP_LEVEL
error occurs.ER_INVALID_GEOJSON_CRS_NOT_TOP_LEVEL
错误。
As specified in the GeoJSON specification, parsing is case-sensitive for the 正如GeoJSON规范中所指定的,解析对GeoJSON输入的type
member of the GeoJSON input (Point
, LineString
, and so forth). type
成员(Point
、LineString
等)是区分大小写的。The specification is silent regarding case sensitivity for other parsing, which in MySQL is not case-sensitive.该规范对其他解析的大小写敏感度保持沉默,而在MySQL中则不区分大小写。
This example shows the parsing result for a simple GeoJSON object. 此示例显示了一个简单GeoJSON对象的解析结果。Observe that the order of coordinates depends on the SRID used.请注意,坐标的顺序取决于所使用的SRID。
mysql>SET @json = '{ "type": "Point", "coordinates": [102.0, 0.0]}';
mysql>SELECT ST_AsText(ST_GeomFromGeoJSON(@json));
+--------------------------------------+ | ST_AsText(ST_GeomFromGeoJSON(@json)) | +--------------------------------------+ | POINT(0 102) | +--------------------------------------+ mysql>SELECT ST_SRID(ST_GeomFromGeoJSON(@json));
+------------------------------------+ | ST_SRID(ST_GeomFromGeoJSON(@json)) | +------------------------------------+ | 4326 | +------------------------------------+ mysql>SELECT ST_AsText(ST_SRID(ST_GeomFromGeoJSON(@json),0));
+-------------------------------------------------+ | ST_AsText(ST_SRID(ST_GeomFromGeoJSON(@json),0)) | +-------------------------------------------------+ | POINT(102 0) | +-------------------------------------------------+