The functions in this section provide convenience operations on geometry values.本节中的函数提供了对几何图形值的方便操作。
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
错误。
For functions that take multiple geometry arguments, if those arguments are not in the same SRS, an 对于采用多个几何参数的函数,如果这些参数不在同一SRS中,则会发生ER_GIS_DIFFERENT_SRIDS
error occurs.ER_GIS_DIFFERENT_SRIDS
错误。
Otherwise, the return value is non-否则,返回值为非NULL
.NULL
。
These convenience functions are available:提供以下便利功能:
ST_Distance_Sphere(
g1
, g2
[, radius
])
Returns the mimimum spherical distance between 返回球体上Point
or MultiPoint
arguments on a sphere, in meters. Point
或MultiPoint
参数之间的最小球面距离,单位为米。(For general-purpose distance calculations, see the (有关一般用途的距离计算,请参见ST_Distance()
function.) ST_distance()
函数。)The optional 可选radius
argument should be given in meters.radius
参数应以米为单位。
If both geometry parameters are valid Cartesian 如果两个几何体参数在SRID 0中都是有效的笛卡尔Point
or MultiPoint
values in SRID 0, the return value is shortest distance between the two geometries on a sphere with the provided radius. Point
或MultiPoint
值,则返回值是具有给定半径的球体上两个几何体之间的最短距离。If omitted, the default radius is 6,370,986 meters, Point X and Y coordinates are interpreted as longitude and latitude, respectively, in degrees.如果省略,则默认半径为6370986米,点X和Y坐标分别解释为经度和纬度,单位为度。
If both geometry parameters are valid 如果两个几何参数都是地理空间参考系(SRS)中的有效Point
or MultiPoint
values in a geographic spatial reference system (SRS), the return value is the shortest distance between the two geometries on a sphere with the provided radius. Point
或MultiPoint
值,则返回值是具有给定半径的球体上两个几何之间的最短距离。If omitted, the default radius is equal to the mean radius, defined as (2a+b)/3, where a is the semi-major axis and b is the semi-minor axis of the SRS.如果省略,默认半径等于平均半径,定义为(2a+b)/3,其中a是SRS的半长轴,b是SRS的半短轴。
ST_Distance_Sphere()
handles its arguments as described in the introduction to this section, with these exceptions:ST_Distance_Sphere()
按本节简介中所述处理其参数,但有以下例外:
Supported geometry argument combinations are 支持的几何参数组合为Point
and Point
, or Point
and MultiPoint
(in any argument order). Point
和Point
,或Point
和MultiPoint
(按任何参数顺序)。If at least one of the geometries is neither 如果至少有一个几何体既非Point
nor MultiPoint
, and its SRID is 0, an ER_NOT_IMPLEMENTED_FOR_CARTESIAN_SRS
error occurs. Point
也非MultiPoint
,并且其SRID为0,则会发生ER_NOT_IMPLEMENTED_FOR_CARTESIAN_SRS
错误。If at least one of the geometries is neither 如果至少有一个几何既非Point
nor MultiPoint
, and its SRID refers to a geographic SRS, an ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
error occurs. Point
也非MultiPoint
,并且其SRID引用地理SRS,则会发生ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
错误。If any geometry refers to a projected SRS, an 如果任何几何体涉及投影的SRS,则会发生ER_NOT_IMPLEMENTED_FOR_PROJECTED_SRS
error occurs.ER_NOT_IMPLEMENTED_FOR_PROJECTED_SRS
错误。
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 如果经度值不在范围(-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. 显示的范围以度为单位。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.由于采用浮点运算,精确的范围限制略有偏差。
If the 如果radius
argument is present but not positive, an ER_NONPOSITIVE_RADIUS
error occurs.radius
参数存在但不是正的,则会发生ER_NONPOSITIVE_RADIUS
错误。
If the distance exceeds the range of a double-precision number, an 如果距离超过双精度数字的范围,则会发生ER_STD_OVERFLOW_ERROR
error occurs.ER_STD_OVERFLOW_ERROR
错误。
mysql>SET @pt1 = ST_GeomFromText('POINT(0 0)');
mysql>SET @pt2 = ST_GeomFromText('POINT(180 0)');
mysql>SELECT ST_Distance_Sphere(@pt1, @pt2);
+--------------------------------+ | ST_Distance_Sphere(@pt1, @pt2) | +--------------------------------+ | 20015042.813723423 | +--------------------------------+
Returns 1 if the argument is geometrically valid, 0 if the argument is not geometrically valid. 如果参数在几何上有效,则返回1;如果参数在几何上无效,则返回0。Geometry validity is defined by the OGC specification.几何有效性由OGC规范定义。
The only valid empty geometry is represented in the form of an empty geometry collection value. 唯一有效的空几何图形以空几何图形集合值的形式表示。在本例中,ST_IsValid()
returns 1 in this case. ST_IsValid()
返回1。MySQL does not support GIS MySQL不支持诸如EMPTY
values such as POINT EMPTY
.POINT EMPTY
之类的GISEMPTY
值。
ST_IsValid()
handles its arguments as described in the introduction to this section, with this exception:ST_IsValid()
按本节简介中所述处理其参数,但有以下例外:
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. 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.由于采用浮点运算,精确的范围限制略有偏差。
mysql>SET @ls1 = ST_GeomFromText('LINESTRING(0 0,-0.00 0,0.0 0)');
mysql>SET @ls2 = ST_GeomFromText('LINESTRING(0 0, 1 1)');
mysql>SELECT ST_IsValid(@ls1);
+------------------+ | ST_IsValid(@ls1) | +------------------+ | 0 | +------------------+ mysql>SELECT ST_IsValid(@ls2);
+------------------+ | ST_IsValid(@ls2) | +------------------+ | 1 | +------------------+
Returns the rectangle that forms the envelope around two points, as a 返回围绕两点形成封套的矩形,如Point
, LineString
, or Polygon
.Point
、LineString
或Polygon
。
Calculations are done using the Cartesian coordinate system rather than on a sphere, spheroid, or on earth.计算是使用笛卡尔坐标系,而不是在球体、球体或地球上进行的。
Given two points 给定两点pt1
and pt2
, ST_MakeEnvelope()
creates the result geometry on an abstract plane like this:pt1
和pt2
,ST_MakeEnvelope()
在抽象平面上创建结果几何体,如下所示:
If 如果pt1
and pt2
are equal, the result is the point pt1
.pt1
和pt2
相等,则结果为点pt1
。
Otherwise, if 否则,如果(
is a vertical or horizontal line segment, the result is the line segment pt1
, pt2
)(
.pt1
, pt2
)(
是垂直或水平线段,则结果是线段pt1
, pt2
)(
。pt1
, pt2
)
Otherwise, the result is a polygon using 否则,结果是使用pt1
and pt2
as diagonal points.pt1
和pt2
作为对角点的多边形。
The result geometry has an SRID of 0.结果几何体的SRID为0。
ST_MakeEnvelope()
handles its arguments as described in the introduction to this section, with these exceptions:ST_MakeEnvelope()
按照本节简介中所述处理其参数,但有以下例外:
If the arguments are not 如果参数不是Point
values, an ER_WRONG_ARGUMENTS
error occurs.Point
值,则会发生ER_WRONG_ARGUMENTS
错误。
An 当两个点的任何坐标值为无穷大或NaN时,会出现ER_GIS_INVALID_DATA
error occurs for the additional condition that any coordinate value of the two points is infinite or NaN
.ER_GIS_INVALID_DATA
错误。
If any 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
错误。
mysql>SET @pt1 = ST_GeomFromText('POINT(0 0)');
mysql>SET @pt2 = ST_GeomFromText('POINT(1 1)');
mysql>SELECT ST_AsText(ST_MakeEnvelope(@pt1, @pt2));
+----------------------------------------+ | ST_AsText(ST_MakeEnvelope(@pt1, @pt2)) | +----------------------------------------+ | POLYGON((0 0,1 0,1 1,0 1,0 0)) | +----------------------------------------+
Simplifies a geometry using the Douglas-Peucker algorithm and returns a simplified value of the same type.使用Douglas Peucker算法简化几何体,并返回相同类型的简化值。
The geometry may be any geometry type, although the Douglas-Peucker algorithm may not actually process every type. 几何体可以是任何几何体类型,尽管Douglas-Peucker算法实际上可能不会处理每种类型。A geometry collection is processed by giving its components one by one to the simplification algorithm, and the returned geometries are put into a geometry collection as result.通过将几何集合的各个组成部分逐一交给简化算法,对几何集合进行处理,并将返回的几何集合放入几何集合中。
The max_distance
argument is the distance (in units of the input coordinates) of a vertex to other segments to be removed. max_distance
参数是顶点到要删除的其他线段的距离(以输入坐标为单位)。Vertices within this distance of the simplified linestring are removed.在简化线串的这个距离内的顶点将被删除。
According to Boost.Geometry, geometries might become invalid as a result of the simplification process, and the process might create self-intersections. 根据Boost.Geometry,由于简化过程,几何可能会变得无效,并且这个过程可能会创建自相交。To check the validity of the result, pass it to 要检查结果的有效性,请将其传递给ST_IsValid()
.ST_IsValid()
。
ST_Simplify()
handles its arguments as described in the introduction to this section, with this exception:ST_Simplify()
按本节简介中所述处理其参数,但有以下例外:
If the 如果max_distance
argument is not positive, or is NaN
, an ER_WRONG_ARGUMENTS
error occurs.max_distance
参数不是正数,或者是NaN
,则会发生ER_WRONG_ARGUMENTS
错误。
mysql>SET @g = ST_GeomFromText('LINESTRING(0 0,0 1,1 1,1 2,2 2,2 3,3 3)');
mysql>SELECT ST_AsText(ST_Simplify(@g, 0.5));
+---------------------------------+ | ST_AsText(ST_Simplify(@g, 0.5)) | +---------------------------------+ | LINESTRING(0 0,0 1,1 1,2 3,3 3) | +---------------------------------+ mysql>SELECT ST_AsText(ST_Simplify(@g, 1.0));
+---------------------------------+ | ST_AsText(ST_Simplify(@g, 1.0)) | +---------------------------------+ | LINESTRING(0 0,3 3) | +---------------------------------+
Validates a geometry according to the OGC specification. 根据OGC规范验证几何体。A geometry can be syntactically well-formed (WKB value plus SRID) but geometrically invalid. 一个几何可以是语法形式良好的(WKB值加SRID),但几何无效。For example, this polygon is geometrically invalid: 例如,此多边形在几何上无效:POLYGON((0 0, 0 0, 0 0, 0 0, 0 0))
如果几何体在语法上格式正确且几何性有效,则ST_Validate()
returns the geometry if it is syntactically well-formed and is geometrically valid, NULL
if the argument is not syntactically well-formed or is not geometrically valid or is NULL
.ST_Validate()
返回该几何体;如果参数在语法上格式不正确或几何体无效或为NULL
,则返回NULL
。
ST_Validate()
can be used to filter out invalid geometry data, although at a cost. ST_Validate()
可用于过滤无效的几何体数据,但要付出一定代价。For applications that require more precise results not tainted by invalid data, this penalty may be worthwhile.对于需要更精确结果而不受无效数据污染的应用程序,这种惩罚可能是值得的。
If the geometry argument is valid, it is returned as is, except that if an input 如果几何体参数有效,则返回原样,但如果输入多边形或多边形具有顺时针环,则在检查有效性之前会反转这些环。Polygon
or MultiPolygon
has clockwise rings, those rings are reversed before checking for validity. If the geometry is valid, the value with the reversed rings is returned.如果几何体有效,则返回带反转环的值。
The only valid empty geometry is represented in the form of an empty geometry collection value. 唯一有效的空几何图形以空几何图形集合值的形式表示。在本例中,ST_Validate()
returns it directly without further checks in this case.ST_Validate()
直接返回它,而无需进一步检查。
As of MySQL 8.0.13, 从MySQL8.0.13开始,ST_Validate()
handles its arguments as described in the introduction to this section, with these exceptions:ST_Validate()
将按照本节简介中所述处理其参数,但有以下例外:
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 如果任何几何体具有地理空间参考系(SRS)的SRID值,则会发生ER_GEOMETRY_PARAM_LATITUDE_OUT_OF_RANGE
error occurs (ER_LATITUDE_OUT_OF_RANGE
prior to MySQL 8.0.12).ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
错误。
Ranges shown are in degrees. 显示的范围以度为单位。The exact range limits deviate slightly due to floating-point arithmetic.由于采用浮点运算,精确的范围限制略有偏差。
Prior to MySQL 8.0.13, 在MySQL8.0.13之前,ST_Validate()
handles its arguments as described in the introduction to this section, with these exceptions:ST_Validate()
按照本节简介中所述处理其参数,但有以下例外:
If the geometry is not syntactically well-formed, the return value is 如果几何体的语法格式不正确,则返回值为NULL
. NULL
。An 不会发生ER_GIS_INVALID_DATA
error does not occur.ER_GIS_INVALID_DATA
错误。
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
错误。
mysql>SET @ls1 = ST_GeomFromText('LINESTRING(0 0)');
mysql>SET @ls2 = ST_GeomFromText('LINESTRING(0 0, 1 1)');
mysql>SELECT ST_AsText(ST_Validate(@ls1));
+------------------------------+ | ST_AsText(ST_Validate(@ls1)) | +------------------------------+ | NULL | +------------------------------+ mysql>SELECT ST_AsText(ST_Validate(@ls2));
+------------------------------+ | ST_AsText(ST_Validate(@ls2)) | +------------------------------+ | LINESTRING(0 0,1 1) | +------------------------------+