Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 35.1Mb
PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  / ...  / Functions and Operators  / Spatial Analysis Functions  / Geometry Property Functions  /  LineString and MultiLineString Property Functions

12.16.7.3 LineString and MultiLineString Property Functions

ALineString consists ofPoint values. You can extract particular points of aLineString, count the number of points that it contains, or obtain its length.

Some functions in this section also work forMultiLineString values.

  • EndPoint(ls)

    ST_EndPoint() andEndPoint() are synonyms. For more information, see the description ofST_EndPoint().

    EndPoint() is deprecated; expect it to be removed in a future MySQL release. UseST_EndPoint() instead.

  • GLength(ls)

    GLength() is a nonstandard name. It corresponds to the OpenGISST_Length() function. (There is an existing SQL functionLength() that calculates the length of string values.)

    GLength() is deprecated; expect it to be removed in a future MySQL release. UseST_Length() instead.

  • IsClosed(ls)

    ST_IsClosed() andIsClosed() are synonyms. For more information, see the description ofST_IsClosed().

    IsClosed() is deprecated; expect it to be removed in a future MySQL release. UseST_IsClosed() instead.

  • NumPoints(ls)

    ST_NumPoints() andNumPoints() are synonyms. For more information, see the description ofST_NumPoints().

    NumPoints() is deprecated; expect it to be removed in a future MySQL release. UseST_NumPoints() instead.

  • PointN(ls,N)

    ST_PointN() andPointN() are synonyms. For more information, see the description ofST_PointN().

    PointN() is deprecated; expect it to be removed in a future MySQL release. UseST_PointN() instead.

  • ST_EndPoint(ls)

    Returns thePoint that is the endpoint of theLineString valuels. If the argument isNULL or an empty geometry, the return value isNULL.

    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)                                   |+----------------------------------------------+

    ST_EndPoint() andEndPoint() are synonyms.

  • ST_IsClosed(ls)

    For aLineString valuels,ST_IsClosed() returns 1 ifls is closed (that is, itsST_StartPoint() andST_EndPoint() values are the same). If the argument isNULL or an empty geometry, the return value isNULL.

    For aMultiLineString valuels,ST_IsClosed() returns 1 ifls is closed (that is, theST_StartPoint() andST_EndPoint() values are the same for eachLineString inls).

    ST_IsClosed() returns 0 ifls is not closed.

    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 |+------------------------------------+

    ST_IsClosed() andIsClosed() are synonyms.

  • ST_Length(ls)

    Returns a double-precision number indicating the length of theLineString orMultiLineString valuels in its associated spatial reference system. The length of aMultiLineString value is equal to the sum of the lengths of its elements. If the argument isNULL or an empty geometry, the return value isNULL.

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';mysql> SELECT ST_Length(ST_GeomFromText(@ls));+---------------------------------+| ST_Length(ST_GeomFromText(@ls)) |+---------------------------------+|              2.8284271247461903 |+---------------------------------+mysql> SET @mls = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';mysql> SELECT ST_Length(ST_GeomFromText(@mls));+----------------------------------+| ST_Length(ST_GeomFromText(@mls)) |+----------------------------------+|                4.242640687119286 |+----------------------------------+

    ST_Length() should be used in preference toGLength(), which has a nonstandard name.

  • ST_NumPoints(ls)

    Returns the number ofPoint objects in theLineString valuels. If the argument isNULL or an empty geometry, the return value isNULL.

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';mysql> SELECT ST_NumPoints(ST_GeomFromText(@ls));+------------------------------------+| ST_NumPoints(ST_GeomFromText(@ls)) |+------------------------------------+|                                  3 |+------------------------------------+

    ST_NumPoints() andNumPoints() are synonyms.

  • ST_PointN(ls,N)

    Returns theN-thPoint in theLinestring valuels. Points are numbered beginning with 1. If any argument isNULL or the geometry argument is an empty geometry, the return value isNULL.

    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)                                   |+----------------------------------------------+

    ST_PointN() andPointN() are synonyms.

  • ST_StartPoint(ls)

    Returns thePoint that is the start point of theLineString valuels. If the argument isNULL or an empty geometry, the return value isNULL.

    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)                                     |+------------------------------------------------+

    ST_StartPoint() andStartPoint() are synonyms.

  • StartPoint(ls)

    ST_StartPoint() andStartPoint() are synonyms. For more information, see the description ofST_StartPoint().

    StartPoint() is deprecated; expect it to be removed in a future MySQL release. UseST_StartPoint() instead.