A LineString
consists of Point
values. LineString
由Point
值组成。You can extract particular points of a 可以提取LineString
, count the number of points that it contains, or obtain its length.LineString
的特定点,计算其包含的点的数量,或获取其长度。
Some functions in this section also work for 本节中的某些函数也适用于MultiLineString
values.MultiLineString
值。
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
错误。
Otherwise, the return value is non-否则,返回值为非NULL
.NULL
。
These functions are available for obtaining linestring properties:这些函数可用于获取线字符串特性:
Returns the 返回Point
that is the endpoint of the LineString
value ls
.Point
,它是LineString
值ls
的端点。
ST_EndPoint()
handles its arguments as described in the introduction to this section.ST_EndPoint()
处理其参数,如本节简介中所述。
mysql>SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT ST_AsText(ST_EndPoint(ST_GeomFromText(@ls)));
+----------------------------------------------+ | ST_AsText(ST_EndPoint(ST_GeomFromText(@ls))) | +----------------------------------------------+ | POINT(3 3) | +----------------------------------------------+
For a 对于LineString
value ls
, ST_IsClosed()
returns 1 if ls
is closed (that is, its ST_StartPoint()
and ST_EndPoint()
values are the same).LineString
值ls
,如果ls
已关闭,则ST_IsClosed()
返回1(即,其ST_StartPoint()
和ST_EndPoint()
值相同)。
For a 对于MultiLineString
value ls
, ST_IsClosed()
returns 1 if ls
is closed (that is, the ST_StartPoint()
and ST_EndPoint()
values are the same for each LineString
in ls
).MultiLineString
值ls
,如果ls
已关闭,则ST_IsClosed()
返回1(即,ls中每个行字符串的ST_StartPoint()
和ST_EndPoint()
值相同)。
如果ls未关闭,则ST_IsClosed()
returns 0 if ls
is not closed, and NULL
if ls
is NULL
.ST_IsClosed()
返回0;如果ls
为NULL
,则返回NULL
。
ST_IsClosed()
handles its arguments as described in the introduction to this section, with this exception:ST_IsClosed()
按本节简介中所述处理其参数,但有以下例外:
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 = 'LineString(1 1,2 2,3 3,2 2)';
mysql>SET @ls2 = 'LineString(1 1,2 2,3 3,1 1)';
mysql>SELECT ST_IsClosed(ST_GeomFromText(@ls1));
+------------------------------------+ | ST_IsClosed(ST_GeomFromText(@ls1)) | +------------------------------------+ | 0 | +------------------------------------+ mysql>SELECT ST_IsClosed(ST_GeomFromText(@ls2));
+------------------------------------+ | ST_IsClosed(ST_GeomFromText(@ls2)) | +------------------------------------+ | 1 | +------------------------------------+ mysql>SET @ls3 = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
mysql>SELECT ST_IsClosed(ST_GeomFromText(@ls3));
+------------------------------------+ | ST_IsClosed(ST_GeomFromText(@ls3)) | +------------------------------------+ | 0 | +------------------------------------+
Returns a double-precision number indicating the length of the 返回一个双精度数字,该数字指示LineString
or MultiLineString
value ls
in its associated spatial reference system. LineString
或MultiLineString
值ls
在其关联的空间参照系中的长度。The length of a MultiLineString
value is equal to the sum of the lengths of its elements.MultiLineString
值的长度等于其元素长度之和。
ST_Length()
computes a result as follows:
If the geometry is a valid 如果几何图形是笛卡尔SRS中的有效LineString
in a Cartesian SRS, the return value is the Cartesian length of the geometry.LineString
,则返回值是几何图形的笛卡尔长度。
If the geometry is a valid 如果几何体是笛卡尔SRS中的有效的MultiLineString
in a Cartesian SRS, the return value is the sum of the Cartesian lengths of its elements.MultiLineString
,则返回值是其元素的笛卡尔长度之和。
If the geometry is a valid 如果几何图形是地理SRS中的有效LineString
in a geographic SRS, the return value is the geodetic length of the geometry in that SRS, in meters.LineString
,则返回值是该SRS中几何图形的大地测量长度(单位:米)。
If the geometry is a valid 如果几何图形是地理SRS中的有效MultiLineString
in a geographic SRS, the return value is the sum of the geodetic lengths of its elements in that SRS, in meters.MultiLineString
,则返回值是该SRS中其元素的大地测量长度之和(以米为单位)。
ST_Length()
handles its arguments as described in the introduction to this section, with these exceptions:ST_Length()
按照本节简介中所述处理其参数,但有以下例外:
If the geometry is not a 如果几何图形不是LineString
or MultiLineString
, the return value is NULL
.LineString
或MultiLineString
,则返回值为NULL
。
If the geometry is geometrically invalid, either the result is an undefined length (that is, it can be any number), or an error occurs.如果几何图形在几何上无效,则结果可能是未定义的长度(也就是说,它可以是任何数字),或者发生错误。
If the length computation result is 如果长度计算结果为+inf
, an ER_DATA_OUT_OF_RANGE
error occurs.+inf
,则会发生ER_DATA_OUT_OF_RANGE
错误。
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.由于采用浮点运算,精确的范围限制略有偏差。
As of MySQL 8.0.16, 从MySQL8.0.16开始,ST_Length()
permits an optional unit
argument that specifies the linear unit for the returned length value. ST_Length()
允许一个可选的unit
参数,指定返回长度值的线性单位。These rules apply:这些规则适用于:
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都用米表示。
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单位”。
mysql>SET @ls = ST_GeomFromText('LineString(1 1,2 2,3 3)');
mysql>SELECT ST_Length(@ls);
+--------------------+ | ST_Length(@ls) | +--------------------+ | 2.8284271247461903 | +--------------------+ mysql>SET @mls = ST_GeomFromText('MultiLineString((1 1,2 2,3 3),(4 4,5 5))');
mysql>SELECT ST_Length(@mls);
+-------------------+ | ST_Length(@mls) | +-------------------+ | 4.242640687119286 | +-------------------+ mysql>SET @ls = ST_GeomFromText('LineString(1 1,2 2,3 3)', 4326);
mysql>SELECT ST_Length(@ls);
+-------------------+ | ST_Length(@ls) | +-------------------+ | 313701.9623204328 | +-------------------+ mysql>SELECT ST_Length(@ls, 'metre');
+-------------------------+ | ST_Length(@ls, 'metre') | +-------------------------+ | 313701.9623204328 | +-------------------------+ mysql>SELECT ST_Length(@ls, 'foot');
+------------------------+ | ST_Length(@ls, 'foot') | +------------------------+ | 1029205.9131247795 | +------------------------+
Returns the number of 返回Point
objects in the LineString
value ls
.LineString
值ls
中的Point
对象数。
ST_NumPoints()
handles its arguments as described in the introduction to this section.ST_NumPoints()
处理其参数,如本节简介中所述。
mysql>SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT ST_NumPoints(ST_GeomFromText(@ls));
+------------------------------------+ | ST_NumPoints(ST_GeomFromText(@ls)) | +------------------------------------+ | 3 | +------------------------------------+
Returns the 返回N
-th Point
in the Linestring
value ls
. Linestring
值ls
中的第N
个点。Points are numbered beginning with 1.点从1开始编号。
ST_PointN()
handles its arguments as described in the introduction to this section.ST_PointN()
处理其参数,如本节简介中所述。
mysql>SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT ST_AsText(ST_PointN(ST_GeomFromText(@ls),2));
+----------------------------------------------+ | ST_AsText(ST_PointN(ST_GeomFromText(@ls),2)) | +----------------------------------------------+ | POINT(2 2) | +----------------------------------------------+
Returns the 返回Point
that is the start point of the LineString
value ls
.Point
,它是LineString
值ls
的起点。
ST_StartPoint()
handles its arguments as described in the introduction to this section.ST_StartPoint()
处理其参数,如本节简介中所述。
mysql>SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT ST_AsText(ST_StartPoint(ST_GeomFromText(@ls)));
+------------------------------------------------+ | ST_AsText(ST_StartPoint(ST_GeomFromText(@ls))) | +------------------------------------------------+ | POINT(1 1) | +------------------------------------------------+