The functions listed in this section do not restrict their argument and accept a geometry value of any type.本节中列出的函数不限制其参数并接受任何类型的几何值。
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 a syntactically well-formed geometry in an undefined spatial reference system (SRS), an 如果任何几何参数是未定义空间参考系(SRS)中语法结构良好的几何体,则会发生ER_SRS_NOT_FOUND
error occurs.ER_SRS_NOT_FOUND
错误。
If any SRID argument is not within the range of a 32-bit unsigned integer, an 如果任何SRID参数不在32位无符号整数的范围内,则会发生ER_DATA_OUT_OF_RANGE
error occurs.ER_DATA_OUT_OF_RANGE
错误。
If any SRID argument refers to an undefined SRS, an 如果任何SRID参数引用未定义的SRS,则会发生ER_SRS_NOT_FOUND
error occurs.ER_SRS_NOT_FOUND
错误。
Otherwise, the return value is non-否则,返回值为非NULL
.NULL
。
These functions are available for obtaining geometry properties:这些函数可用于获取几何图形特性:
Returns the inherent dimension of the geometry value 返回几何体值g
. g
的固有尺寸。The dimension can be −1, 0, 1, or 2. 尺寸可以是1、0、1或2。The meaning of these values is given in Section 11.4.2.2, “Geometry Class”.这些值的含义请参阅第11.4.2.2节“几何体类”。
ST_Dimension()
handles its arguments as described in the introduction to this section.ST_Dimension()
处理其参数,如本节简介中所述。
mysql> SELECT ST_Dimension(ST_GeomFromText('LineString(1 1,2 2)'));
+------------------------------------------------------+
| ST_Dimension(ST_GeomFromText('LineString(1 1,2 2)')) |
+------------------------------------------------------+
| 1 |
+------------------------------------------------------+
Returns the minimum bounding rectangle (MBR) for the geometry value 返回几何体值g
. g
的最小边界矩形(MBR)。The result is returned as a 结果将作为Polygon
value that is defined by the corner points of the bounding box:Polygon
值返回,该值由边界框的角点定义:
POLYGON((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
mysql> SELECT ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,2 2)')));
+----------------------------------------------------------------+
| ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,2 2)'))) |
+----------------------------------------------------------------+
| POLYGON((1 1,2 1,2 2,1 2,1 1)) |
+----------------------------------------------------------------+
If the argument is a point or a vertical or horizontal line segment, 如果参数是一个点或垂直或水平线段,则ST_Envelope()
returns the point or the line segment as its MBR rather than returning an invalid polygon:ST_Envelope()
返回该点或线段作为其MBR,而不是返回无效的多边形:
mysql> SELECT ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,1 2)')));
+----------------------------------------------------------------+
| ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,1 2)'))) |
+----------------------------------------------------------------+
| LINESTRING(1 1,1 2) |
+----------------------------------------------------------------+
ST_Envelope()
handles its arguments as described in the introduction to this section, with this exception:ST_Envelope()
按本节简介中所述处理其参数,但有以下例外:
If the geometry has an SRID value for a geographic spatial reference system (SRS), an 如果几何体具有地理空间参考系(SRS)的SRID值,则会发生ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
error occurs.ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
错误。
Returns a binary string indicating the name of the geometry type of which the geometry instance 返回一个二进制字符串,该字符串指示几何体实例g
is a member. g
所属的几何体类型的名称。The name corresponds to one of the instantiable 该名称对应于一个可实例化的Geometry
subclasses.Geometry
子类。
ST_GeometryType()
handles its arguments as described in the introduction to this section.ST_GeometryType()
处理其参数,如本节简介中所述。
mysql> SELECT ST_GeometryType(ST_GeomFromText('POINT(1 1)'));
+------------------------------------------------+
| ST_GeometryType(ST_GeomFromText('POINT(1 1)')) |
+------------------------------------------------+
| POINT |
+------------------------------------------------+
This function is a placeholder that returns 1 for an empty geometry collection value or 0 otherwise.此函数是一个占位符,对于空的几何图形集合值返回1,否则返回0。
The only valid empty geometry is represented in the form of an empty geometry collection value. 唯一有效的空几何图形以空几何图形集合值的形式表示。MySQL does not support GIS MySQL不支持诸如EMPTY
values such as POINT EMPTY
.POINT EMPTY
之类的GIS空值。
ST_IsEmpty()
handles its arguments as described in the introduction to this section.ST_IsEmpty()
处理其参数,如本节简介中所述。
Returns 1 if the geometry value 如果几何体值g
is simple according to the ISO SQL/MM Part 3: Spatial standard. g
仅仅是根据ISO SQL/MM第3部分:空间标准,则返回1。如果参数不简单,则ST_IsSimple()
returns 0 if the argument is not simple.ST_IsSimple()
返回0。
The descriptions of the instantiable geometric classes given under Section 11.4.2, “The OpenGIS Geometry Model” include the specific conditions that cause class instances to be classified as not simple.第11.4.2节,“OpenGIS几何模型”中给出的可实例化几何类的描述包括导致类实例被分类为不简单的特定条件。
ST_IsSimple()
handles its arguments as described in the introduction to this section, with this exception:ST_IsSimple()
按本节简介中所述处理其参数,但有以下例外:
If the geometry has a geographic SRS with 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_GEOMETRY_PARAM_LONGITUDE_OUT_OF_RANGE
error occurs (ER_LONGITUDE_OUT_OF_RANGE
prior to MySQL 8.0.12).ER_GEOMETRY_PARAM_LONGITUDE_OUT_OF_RANGE
错误(在MySQL 8.0.12之前发生ER_LONGITUDE_OUT_OF_RANGE
错误)。
If a latitude value is not in the range [−90, 90], an 如果纬度值不在范围[-90,90]内,则会发生ER_GEOMETRY_PARAM_LATITUDE_OUT_OF_RANGE
error occurs (ER_LATITUDE_OUT_OF_RANGE
prior to MySQL 8.0.12).ER_GEOMETRY_PARAM_LATITUDE_OUT_OF_RANGE
错误(在MySQL 8.0.12之前发生ER_LATITUDE_OUT_OF_RANGE
错误)。
Ranges shown are in degrees. 显示的范围以度为单位。The exact range limits deviate slightly due to floating-point arithmetic.由于采用浮点运算,精确的范围限制略有偏差。
With a single argument representing a valid geometry object 对于表示有效几何体对象g的单个参数,g
, ST_SRID()
returns an integer indicating the ID of the spatial reference system (SRS) associated with g
.ST_SRID()
返回一个整数,该整数指示与g
关联的空间参照系(SRS)的ID。
With the optional second argument representing a valid SRID value, 对于表示有效SRID值的可选第二个参数,ST_SRID()
returns an object with the same type as its first argument with an SRID value equal to the second argument. ST_SRID()
返回与第一个参数类型相同的对象,SRID值等于第二个参数。This only sets the SRID value of the object; it does not perform any transformation of coordinate values.这只设置对象的SRID值;它不执行坐标值的任何转换。
ST_SRID()
handles its arguments as described in the introduction to this section, with this exception:ST_SRID()
按本节简介中所述处理其参数,但有以下例外:
For the single-argument syntax, 对于单参数语法,ST_SRID()
returns the geometry SRID even if it refers to an undefined SRS. ST_SRID()
返回几何体SRID,即使它引用了未定义的SRS。An 不会发生ER_SRS_NOT_FOUND
error does not occur.ER_SRS_NOT_FOUND
错误。
ST_SRID(
and g
, target_srid
)ST_Transform(
differ as follows:g
, target_srid
)
ST_SRID()
changes the geometry SRID value without transforming its coordinates.ST_SRID()
更改几何体SRID值而不转换其坐标。
ST_Transform()
transforms the geometry coordinates in addition to changing its SRID value.ST_Transform()
除了更改其SRID值之外,还将变换几何体坐标。
mysql>SET @g = ST_GeomFromText('LineString(1 1,2 2)', 0);
mysql>SELECT ST_SRID(@g);
+-------------+ | ST_SRID(@g) | +-------------+ | 0 | +-------------+ mysql>SET @g = ST_SRID(@g, 4326);
mysql>SELECT ST_SRID(@g);
+-------------+ | ST_SRID(@g) | +-------------+ | 4326 | +-------------+
It is possible to create a geometry in a particular SRID by passing to 通过将MySQL创建空间值的特定函数之一的结果以及一个SRID值传递给ST_SRID()
the result of one of the MySQL-specific functions for creating spatial values, along with an SRID value. ST_SRID()
,可以在特定的SRID中创建几何体。For example:例如:
SET @g1 = ST_SRID(Point(1, 1), 4326);
However, that method creates the geometry in SRID 0, then casts it to SRID 4326 (WGS 84). 但是,该方法在SRID 0中创建几何体,然后将其强制转换为SRID 4326(WGS 84)。A preferable alternative is to create the geometry with the correct spatial reference system to begin with. 一个更好的选择是创建具有正确的空间参照系的几何图形。For example:例如:
SET @g1 = ST_PointFromText('POINT(1 1)', 4326); SET @g1 = ST_GeomFromText('POINT(1 1)', 4326);
The two-argument form of ST_SRID()
is useful for tasks such as correcting or changing the SRS of geometries that have an incorrect SRID.ST_SRID()
的双参数形式对于纠正或更改SRID不正确的几何体的SRS等任务非常有用。