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.MySQL支持本节中列出的函数,用于将几何值从内部几何格式转换为WKT或WKB格式,或交换X和Y坐标的顺序。
There are also functions to convert a string from WKT or WKB format to internal geometry format. 还有一些函数可以将字符串从WKT或WKB格式转换为内部几何格式。See Section 12.17.3, “Functions That Create Geometry Values from WKT Values”, and Section 12.17.4, “Functions That Create Geometry Values from WKB Values”.参见第12.17.3节,“从WKT值创建几何值的函数”和第12.17.4节,“从WKB值创建几何值的函数”。
Functions such as 接受WKT ST_GeomFromText()
that accept WKT geometry collection arguments understand both OpenGIS 'GEOMETRYCOLLECTION EMPTY'
standard syntax and MySQL 'GEOMETRYCOLLECTION()'
nonstandard syntax. geometry
集合参数的函数,如ST_geometryfromtext()
,既理解OpenGIS的'GEOMETRYCOLLECTION EMPTY'
标准语法,也理解MySQL的'GEOMETRYCOLLECTION()'
非标准语法。Another way to produce an empty geometry collection is by calling 生成空几何体集合的另一种方法是不带参数调用GeometryCollection()
with no arguments. GeometryCollection()
。Functions such as 生成WKT值的函数(如ST_AsWKT()
that produce WKT values produce 'GEOMETRYCOLLECTION EMPTY'
standard syntax:ST_AsWKT()
)将生成'GEOMETRYCOLLECTION EMPTY'
标准语法:
mysql>SET @s1 = ST_GeomFromText('GEOMETRYCOLLECTION()');
mysql>SET @s2 = ST_GeomFromText('GEOMETRYCOLLECTION EMPTY');
mysql>SELECT ST_AsWKT(@s1), ST_AsWKT(@s2);
+--------------------------+--------------------------+ | ST_AsWKT(@s1) | ST_AsWKT(@s2) | +--------------------------+--------------------------+ | GEOMETRYCOLLECTION EMPTY | GEOMETRYCOLLECTION EMPTY | +--------------------------+--------------------------+ mysql>SELECT ST_AsWKT(GeomCollection());
+----------------------------+ | ST_AsWKT(GeomCollection()) | +----------------------------+ | GEOMETRYCOLLECTION EMPTY | +----------------------------+
Unless otherwise specified, functions in this section handle their geometry arguments as follows:除非另有规定,否则本节中的函数按如下方式处理其几何参数:
If any argument is 如果任何参数为NULL
, the return value is NULL
.NULL
,则返回值为NULL
。
If any geometry argument is not a syntactically well-formed geometry, an 如果任何几何参数不是语法格式良好的几何体,则会发生ER_GIS_INVALID_DATA
error occurs.ER_GIS_INVALID_DATA
错误。
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.ER_WARN_SRS_NOT_FOUND_AXIS_ORDER
警告。
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
参数来覆盖默认的轴顺序。options
consists of a list of comma-separated
. key
=value
options
由逗号分隔的
列表组成。key
=value
The only permitted 唯一允许的key
value is axis-order
, with permitted values of lat-long
, long-lat
and srid-defined
(the default).key
值是axis-order
,允许值为lat-long
、long-lat
和srid-defined
(默认值)。
If the 如果options
argument is NULL
, the return value is NULL
. options
参数为NULL
,则返回值为NULL
。If the 如果options
argument is invalid, an error occurs to indicate why.options
参数无效,则会出现一个错误来说明原因。
Otherwise, the return value is non-否则,返回值为非NULL
.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.将内部几何图形格式的值转换为其WKB表示形式,并返回二进制结果。
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.options
参数来覆盖默认的轴顺序。
ST_AsBinary()
and ST_AsWKB()
handle their arguments as described in the introduction to this section.ST_AsBinary()
和ST_AsWKB()
处理它们的参数,如本节简介中所述。
mysql>SET @g = ST_LineFromText('LINESTRING(0 5,5 10,10 15)', 4326);
mysql>SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g)));
+-----------------------------------------+ | ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g))) | +-----------------------------------------+ | LINESTRING(5 0,10 5,15 10) | +-----------------------------------------+ mysql>SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=long-lat')));
+----------------------------------------------------------------+ | ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=long-lat'))) | +----------------------------------------------------------------+ | LINESTRING(0 5,5 10,10 15) | +----------------------------------------------------------------+ mysql>SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=lat-long')));
+----------------------------------------------------------------+ | ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=lat-long'))) | +----------------------------------------------------------------+ | LINESTRING(5 0,10 5,15 10) | +----------------------------------------------------------------+
ST_AsText(
, g
[, options
])ST_AsWKT(
g
[, options
])
Converts a value in internal geometry format to its WKT representation and returns the string result.将内部几何图形格式的值转换为其WKT表示形式,并返回字符串结果。
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.options
参数来覆盖默认的轴顺序。
ST_AsText()
and ST_AsWKT()
handle their arguments as described in the introduction to this section.ST_AsText()
和ST_AsWKT()
处理它们的参数,如本节简介中所述。
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) | +--------------------------------+
Output for MultiPoint
values includes parentheses around each point. MultiPoint
的输出包括围绕每个点的圆括号。For example:例如:
mysql> SELECT ST_AsText(ST_GeomFromText(@mp));
+---------------------------------+
| ST_AsText(ST_GeomFromText(@mp)) |
+---------------------------------+
| MULTIPOINT((1 1),(2 2),(3 3)) |
+---------------------------------+
Accepts an argument in internal geometry format, swaps the X and Y values of each coordinate pair within the geometry, and returns the result.接受内部几何图形格式的参数,交换几何图形中每个坐标对的X和Y值,并返回结果。
ST_SwapXY()
handles its arguments as described in the introduction to this section.ST_SwapXY()
处理其参数,如本节简介中所述。
mysql>SET @g = ST_LineFromText('LINESTRING(0 5,5 10,10 15)');
mysql>SELECT ST_AsText(@g);
+----------------------------+ | ST_AsText(@g) | +----------------------------+ | LINESTRING(0 5,5 10,10 15) | +----------------------------+ mysql>SELECT ST_AsText(ST_SwapXY(@g));
+----------------------------+ | ST_AsText(ST_SwapXY(@g)) | +----------------------------+ | LINESTRING(5 0,10 5,15 10) | +----------------------------+