The OpenGIS specification defines the following functions to test the relationship between two geometry values OpenGIS规范定义了以下函数,使用精确的对象形状来测试两个几何值g1
and g2
, using precise object shapes. g1
和g2
之间的关系。The return values 1 and 0 indicate true and false, respectively, except that distance functions return distance values.返回值1和0分别表示true
和false
,但距离函数返回距离值。
Functions in this section detect arguments in either Cartesian or geographic spatial reference systems (SRSs), and return results appropriate to the SRS.本节中的函数检测笛卡尔坐标系或地理空间参考系(SRS)中的参数,并返回适合SRS的结果。
Unless otherwise specified, functions in this section handle their geometry arguments as follows:除非另有规定,否则本节中的函数按如下方式处理其几何参数:
If any argument is 如果任何参数为NULL
or any geometry argument is an empty geometry, 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
错误。
If any geometry argument is geometrically invalid, either the result is true or false (it is undefined which), or an error occurs.如果任何几何参数在几何上无效,则结果为真或假(未定义),或者发生错误。
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_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.由于采用浮点运算,精确的范围限制略有偏差。
Otherwise, the return value is non-否则,返回值为非NULL
.NULL
。
Some functions in this section permit a unit argument that specifies the length unit for the return value. 本节中的某些函数允许使用单位参数来指定返回值的长度单位。Unless otherwise specified, functions handle their unit argument as follows:除非另有规定,函数按如下方式处理其单位参数:
A unit is supported if it is found in the 如果在INFORMATION_SCHEMA
ST_UNITS_OF_MEASURE
table. INFORMATION_SCHEMA
ST_UNITS_OF_MEASURE
表中找到某个单位,则支持该单位。See Section 26.3.37, “The INFORMATION_SCHEMA ST_UNITS_OF_MEASURE Table”.请参阅第26.3.37节,“测量表的信息模式ST单位”。
If a unit is specified but not supported by MySQL, an 如果MySQL指定了一个单元但不支持它,则会发生ER_UNIT_NOT_FOUND
error occurs.ER_UNIT_NOT_FOUND
错误。
If a supported linear unit is specified and the SRID is 0, an 如果指定了支持的线性单位,并且SRID为0,则会发生ER_GEOMETRY_IN_UNKNOWN_LENGTH_UNIT
error occurs.ER_GEOMETRY_IN_UNKNOWN_LENGTH_UNIT
错误。
If a supported linear unit is specified and the SRID is not 0, the result is in that unit.如果指定了受支持的线性单位,并且SRID不是0,则结果以该单位为单位。
If a unit is not specified, the result is in the unit of the SRS of the geometries, whether Cartesian or geographic. 如果未指定单位,则结果以几何图形的SRS为单位,无论是笛卡尔坐标还是地理坐标。Currently, all MySQL SRSs are expressed in meters.目前,所有MySQL SRS都用米表示。
These object-shape functions are available for testing geometry relationships:这些对象形状函数可用于测试几何关系:
Returns 1 or 0 to indicate whether 返回1或0以指示g1
completely contains g2
. g1
是否完全包含g2
。This tests the opposite relationship as 这将测试与ST_Within()
.ST_Within()
相反的关系。
ST_Contains()
handles its arguments as described in the introduction to this section.ST_Contains()
处理其参数,如本节简介中所述。
Two geometries spatially cross if their spatial relation has the following properties:如果两个几何图形的空间关系具有以下特性,则它们空间上相交:
Unless 除非g1
and g2
are both of dimension 1: g1
crosses g2
if the interior of g2
has points in common with the interior of g1
, but g2
does not cover the entire interior of g1
.g1
和g2
都是尺寸1:如果g2
的内部与g1
的内部有共同点,但g2
不覆盖g1
的整个内部,则g1
穿过g2
。
If both 如果g1
and g2
are of dimension 1: If the lines cross each other in a finite number of points (that is, no common line segments, only single points in common).g1
和g2
的尺寸都为1:如果直线在有限个点上相互交叉(即,没有公共线段,只有公共的单个点)。
This function returns 1 or 0 to indicate whether 此函数返回1或0以指示g1
spatially crosses g2
.g1
是否在空间上穿过g2
。
ST_Crosses()
handles its arguments as described in the introduction to this section except that the return value is NULL
for these additional conditions:ST_crosss()
按本节简介中所述处理其参数,但对于以下附加条件,返回值为NULL
:
g1
is of dimension 2 (Polygon
or MultiPolygon
).g1
的尺寸为2(Polygon
或MultiPolygon
)。
g2
is of dimension 1 (Point
or MultiPoint
).g2
的维数为1(Point
或MultiPoint
)。
Returns 1 or 0 to indicate whether 返回1或0以指示g1
is spatially disjoint from (does not intersect) g2
.g1
是否与g2
在空间上不相交。
ST_Disjoint()
handles its arguments as described in the introduction to this section.ST_Disjoint()
处理其参数,如本节简介中所述。
Returns the distance between 返回g1
and g2
, measured in the length unit of the spatial reference system (SRS) of the geometry arguments, or in the unit of the optional unit
argument if that is specified.g1
和g2
之间的距离,测量单位为几何参数的空间参考系(SRS)的长度单位,或者指定了可选单位参数的单位(如果指定)。
This function processes geometry collections by returning the shortest distance among all combinations of the components of the two geometry arguments.此函数通过返回两个几何参数的所有组件组合中的最短距离来处理几何集合。
ST_Distance()
handles its geometry arguments as described in the introduction to this section, with these exceptions:ST_Distance()
按本节简介中所述处理其几何参数,但有以下例外:
ST_Distance()
detects arguments in a geographic (ellipsoidal) spatial reference system and returns the geodetic distance on the ellipsoid. ST_Distance()
检测地理(椭球体)空间参照系中的参数,并返回椭球体上的大地距离。As of MySQL 8.0.18, 从MySQL 8.0.18开始,ST_Distance()
supports distance calculations for geographic SRS arguments of all geometry types. ST_Distance()
支持所有几何体类型的地理SRS参数的距离计算。Prior to MySQL 8.0.18, the only permitted geographic argument types are 在MySQL 8.0.18之前,唯一允许的地理参数类型是Point
and Point
, or Point
and MultiPoint
(in any argument order). Point
和Point
,或者Point
和MultiPoint
(按任何参数顺序)。If called with other geometry type argument combinations in a geographic SRS, an 如果使用地理SRS中的其他几何类型参数组合调用,则会发生ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
error occurs.ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
错误。
If any argument is geometrically invalid, either the result is an undefined distance (that is, it can be any number), or an error occurs.如果任何参数在几何上无效,则结果可能是未定义的距离(即,它可以是任何数字),或者发生错误。
If an intermediate or final result produces 如果中间或最终结果产生NaN
or a negative number, an ER_GIS_INVALID_DATA
error occurs.NaN
或负数,则会发生ER_GIS_INVALID_DATA
错误。
As of MySQL 8.0.14, 从MySQL8.0.14开始,ST_Distance()
permits an optional unit
argument that specifies the linear unit for the returned distance value. ST_Distance()
允许一个可选的unit参数,指定返回距离值的线性单位。ST_Distance()
handles its unit
argument as described in the introduction to this section.ST_Distance()
处理其unit
参数,如本节简介中所述。
mysql>SET @g1 = ST_GeomFromText('POINT(1 1)');
mysql>SET @g2 = ST_GeomFromText('POINT(2 2)');
mysql>SELECT ST_Distance(@g1, @g2);
+-----------------------+ | ST_Distance(@g1, @g2) | +-----------------------+ | 1.4142135623730951 | +-----------------------+ mysql>SET @g1 = ST_GeomFromText('POINT(1 1)', 4326);
mysql>SET @g2 = ST_GeomFromText('POINT(2 2)', 4326);
mysql>SELECT ST_Distance(@g1, @g2);
+-----------------------+ | ST_Distance(@g1, @g2) | +-----------------------+ | 156874.3859490455 | +-----------------------+ mysql>SELECT ST_Distance(@g1, @g2, 'metre');
+--------------------------------+ | ST_Distance(@g1, @g2, 'metre') | +--------------------------------+ | 156874.3859490455 | +--------------------------------+ mysql>SELECT ST_Distance(@g1, @g2, 'foot');
+-------------------------------+ | ST_Distance(@g1, @g2, 'foot') | +-------------------------------+ | 514679.7439273146 | +-------------------------------+
For the special case of distance calculations on a sphere, see the 有关在球体上计算距离的特殊情况,请参见ST_Distance_Sphere()
function.ST_distance_sphere()
函数。
Returns 1 or 0 to indicate whether 返回1或0以指示g1
is spatially equal to g2
.g1
在空间上是否等于g2
。
ST_Equals()
handles its arguments as described in the introduction to this section, except that it does not return NULL
for empty geometry arguments.ST_Equals()
按本节简介中所述处理其参数,但对于空的几何参数,它不返回NULL
。
mysql>SET @g1 = Point(1,1), @g2 = Point(2,2);
mysql>SELECT ST_Equals(@g1, @g1), ST_Equals(@g1, @g2);
+---------------------+---------------------+ | ST_Equals(@g1, @g1) | ST_Equals(@g1, @g2) | +---------------------+---------------------+ | 1 | 0 | +---------------------+---------------------+
ST_FrechetDistance(
g1
, g2
[, unit
])
Returns the discrete Fréchet distance between two geometries, reflecting how similar the geometries are. 返回两个几何体之间的离散傅立叶距离,反映几何体的相似程度。The result is a double-precision number measured in the length unit of the spatial reference system (SRS) of the geometry arguments, or in the length unit of the 结果是以几何参数的空间参考系(SRS)的长度单位或unit
argument if that argument is given.unit
参数的长度单位(如果给定该参数)测量的双精度数。
This function implements the discrete Fréchet distance, which means it is restricted to distances between the points of the geometries. 此函数实现离散的傅立叶距离,这意味着它仅限于几何图形点之间的距离。For example, given two 例如,给定两个LineString
arguments, only the points explicitly mentioned in the geometries are considered. LineString
参数,只考虑几何图形中明确提到的点。Points on the line segments between these points are not considered.不考虑这些点之间线段上的点。
ST_FrechetDistance()
handles its geometry arguments as described in the introduction to this section, with these exceptions:
The geometries may have a Cartesian or geographic SRS, but only 这些几何图形可能具有笛卡尔坐标或地理坐标,但仅支持LineString
values are supported. LineString
值。If the arguments are in the same Cartesian or geographic SRS, but either is not a 如果参数在同一个笛卡尔或地理SRS中,但不是一个LineString
, an ER_NOT_IMPLEMENTED_FOR_CARTESIAN_SRS
or ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
error occurs, depending on the SRS type.LineString
,则根据SRS类型,会发生ER_NOT_IMPLEMENTED_FOR_CARTESIAN_SRS
错误或ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
错误。
ST_FrechetDistance()
handles its optional unit
argument as described in the introduction to this section.ST_FrechetDistance()
处理可选的unit参数,如本节简介中所述。
mysql>SET @ls1 = ST_GeomFromText('LINESTRING(0 0,0 5,5 5)');
mysql>SET @ls2 = ST_GeomFromText('LINESTRING(0 1,0 6,3 3,5 6)');
mysql>SELECT ST_FrechetDistance(@ls1, @ls2);
+--------------------------------+ | ST_FrechetDistance(@ls1, @ls2) | +--------------------------------+ | 2.8284271247461903 | +--------------------------------+ mysql>SET @ls1 = ST_GeomFromText('LINESTRING(0 0,0 5,5 5)', 4326);
mysql>SET @ls2 = ST_GeomFromText('LINESTRING(0 1,0 6,3 3,5 6)', 4326);
mysql>SELECT ST_FrechetDistance(@ls1, @ls2);
+--------------------------------+ | ST_FrechetDistance(@ls1, @ls2) | +--------------------------------+ | 313421.1999416798 | +--------------------------------+ mysql>SELECT ST_FrechetDistance(@ls1, @ls2, 'foot');
+----------------------------------------+ | ST_FrechetDistance(@ls1, @ls2, 'foot') | +----------------------------------------+ | 1028284.7767115477 | +----------------------------------------+
This function was added in MySQL 8.0.23.MySQL 8.0.23中增加了这个函数。
ST_HausdorffDistance(
g1
, g2
[, unit
])
Returns the discrete Hausdorff distance between two geometries, reflecting how similar the geometries are. 返回两个几何体之间的离散Hausdorff距离,反映几何体的相似程度。The result is a double-precision number measured in the length unit of the spatial reference system (SRS) of the geometry arguments, or in the length unit of the 结果是以几何参数的空间参考系(SRS)的长度单位或unit
argument if that argument is given.unit
参数的长度单位(如果给定该参数)测量的双精度数。
This function implements the discrete Hausdorff distance, which means it is restricted to distances between the points of the geometries. 这个函数实现了离散的Hausdorff距离,这意味着它被限制在几何图形的点之间的距离。For example, given two 例如,给定两个LineString
arguments, only the points explicitly mentioned in the geometries are considered. LineString
参数,只考虑几何图形中明确提到的点。Points on the line segments between these points are not considered.不考虑这些点之间线段上的点。
ST_HausdorffDistance()
handles its geometry arguments as described in the introduction to this section, with these exceptions:ST_hausdorffdance()
处理其几何参数,如本节简介中所述,但有以下例外:
If the geometry arguments are in the same Cartesian or geographic SRS, but are not in a supported combination, an 如果几何参数在同一个笛卡尔或地理SRS中,但不在受支持的组合中,则根据SRS类型,会发生ER_NOT_IMPLEMENTED_FOR_CARTESIAN_SRS
or ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
error occurs, depending on the SRS type. ER_NOT_IMPLEMENTED_FOR_CARTESIAN_SRS
或ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
错误。These combinations are supported:支持以下组合:
LineString
and LineString
LineString
和LineString
Point
and MultiPoint
Point
和MultiPoint
LineString
and MultiLineString
LineString
和MultiLineString
MultiPoint
and MultiPoint
MultiPoint
和MultiPoint
MultiLineString
and MultiLineString
MultiLineString
和MultiLineString
ST_HausdorffDistance()
handles its optional unit
argument as described in the introduction to this section.ST_hausdorffdance()
处理可选的unit
参数,如本节简介中所述。
mysql>SET @ls1 = ST_GeomFromText('LINESTRING(0 0,0 5,5 5)');
mysql>SET @ls2 = ST_GeomFromText('LINESTRING(0 1,0 6,3 3,5 6)');
mysql>SELECT ST_HausdorffDistance(@ls1, @ls2);
+----------------------------------+ | ST_HausdorffDistance(@ls1, @ls2) | +----------------------------------+ | 1 | +----------------------------------+ mysql>SET @ls1 = ST_GeomFromText('LINESTRING(0 0,0 5,5 5)', 4326);
mysql>SET @ls2 = ST_GeomFromText('LINESTRING(0 1,0 6,3 3,5 6)', 4326);
mysql>SELECT ST_HausdorffDistance(@ls1, @ls2);
+----------------------------------+ | ST_HausdorffDistance(@ls1, @ls2) | +----------------------------------+ | 111319.49079326246 | +----------------------------------+ mysql>SELECT ST_HausdorffDistance(@ls1, @ls2, 'foot');
+------------------------------------------+ | ST_HausdorffDistance(@ls1, @ls2, 'foot') | +------------------------------------------+ | 365221.4264870815 | +------------------------------------------+
This function was added in MySQL 8.0.23.MySQL 8.0.23中增加了这个函数。
Returns 1 or 0 to indicate whether 返回1或0以指示g1
spatially intersects g2
.g1
是否在空间上与g2
相交。
ST_Intersects()
handles its arguments as described in the introduction to this section.ST_Intersects()
处理其参数,如本节简介中所述。
Two geometries spatially overlap if they intersect and their intersection results in a geometry of the same dimension but not equal to either of the given geometries.如果两个几何体相交,则它们在空间上会重叠,并且它们的相交会导致一个尺寸相同但不等于给定几何体中任何一个的几何体。
This function returns 1 or 0 to indicate whether 此函数返回1或0,以指示g1
spatially overlaps g2
.g1
在空间上是否与g2
重叠。
ST_Overlaps()
handles its arguments as described in the introduction to this section except that the return value is NULL
for the additional condition that the dimensions of the two geometries are not equal.ST_Overlaps()
按照本节简介中所述处理其参数,但如果两个几何体的尺寸不相等,则返回值为NULL
。
Two geometries spatially touch if their interiors do not intersect, but the boundary of one of the geometries intersects either the boundary or the interior of the other.如果两个几何体的内部不相交,但其中一个几何体的边界与另一个几何体的边界或内部相交,则两个几何体在空间上相互接触。
This function returns 1 or 0 to indicate whether 此函数返回1或0以指示g1
spatially touches g2
.g1
是否在空间上接触g2
。
ST_Touches()
handles its arguments as described in the introduction to this section except that the return value is NULL
for the additional condition that both geometries are of dimension 0 (Point
or MultiPoint
).ST_touchs()
按照本节简介中所述处理其参数,但如果两个几何体的维数都为0(点或多点),则返回值为NULL
。
Returns 1 or 0 to indicate whether 返回1或0以指示g1
is spatially within g2
. g1
在空间上是否在g2
内。This tests the opposite relationship as 这将测试与ST_Contains()
.ST_Contains()
相反的关系。
ST_Within()
handles its arguments as described in the introduction to this section.ST_Within()
处理其参数,如本节简介中所述。