Documentation Home
MySQL 5.5 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 27.1Mb
PDF (A4) - 27.2Mb
PDF (RPM) - 26.0Mb
HTML Download (TGZ) - 6.5Mb
HTML Download (Zip) - 6.5Mb
HTML Download (RPM) - 5.6Mb
Man Pages (TGZ) - 170.8Kb
Man Pages (Zip) - 279.3Kb
Info (Gzip) - 2.6Mb
Info (Zip) - 2.6Mb
Excerpts from this Manual

MySQL 5.5 Reference Manual  /  ...  /  LineString and MultiLineString Property Functions

12.15.7.3 LineString and MultiLineString Property Functions

A LineString consists of Point values. You can extract particular points of a LineString, count the number of points that it contains, or obtain its length.

Some functions in this section also work for MultiLineString values.

  • EndPoint(ls)

    Returns the Point that is the endpoint of the LineString value ls. If the argument is NULL or an empty geometry, the return value is NULL.

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(EndPoint(GeomFromText(@ls)));
    +-------------------------------------+
    | AsText(EndPoint(GeomFromText(@ls))) |
    +-------------------------------------+
    | POINT(3 3)                          |
    +-------------------------------------+
  • GLength(ls)

    Returns a double-precision number indicating the length of the LineString or MultiLineString value ls in its associated spatial reference. The length of a MultiLineString value is equal to the sum of the lengths of its elements. If the argument is NULL or an empty geometry, the return value is NULL.

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

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

  • IsClosed(ls)

    For a LineString value ls, IsClosed() returns 1 if ls is closed (that is, its StartPoint() and EndPoint() values are the same). If the argument is NULL or an empty geometry, the return value is NULL.

    For a MultiLineString value ls, IsClosed() returns 1 if ls is closed (that is, the StartPoint() and EndPoint() values are the same for each LineString in ls).

    IsClosed() returns 0 if ls 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 IsClosed(GeomFromText(@ls1));
    +------------------------------+
    | IsClosed(GeomFromText(@ls1)) |
    +------------------------------+
    |                            0 |
    +------------------------------+
    
    mysql> SELECT IsClosed(GeomFromText(@ls2));
    +------------------------------+
    | IsClosed(GeomFromText(@ls2)) |
    +------------------------------+
    |                            1 |
    +------------------------------+
    
    mysql> SET @ls3 = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
    
    mysql> SELECT IsClosed(GeomFromText(@ls3));
    +------------------------------+
    | IsClosed(GeomFromText(@ls3)) |
    +------------------------------+
    |                            0 |
    +------------------------------+
  • NumPoints(ls)

    Returns the number of Point objects in the LineString value ls. If the argument is NULL or an empty geometry, the return value is NULL.

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT NumPoints(GeomFromText(@ls));
    +------------------------------+
    | NumPoints(GeomFromText(@ls)) |
    +------------------------------+
    |                            3 |
    +------------------------------+
  • PointN(ls, N)

    Returns the N-th Point in the Linestring value ls. Points are numbered beginning with 1. If any argument is NULL or the geometry argument is an empty geometry, the return value is NULL.

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(PointN(GeomFromText(@ls),2));
    +-------------------------------------+
    | AsText(PointN(GeomFromText(@ls),2)) |
    +-------------------------------------+
    | POINT(2 2)                          |
    +-------------------------------------+
  • StartPoint(ls)

    Returns the Point that is the start point of the LineString value ls. If the argument is NULL or an empty geometry, the return value is NULL.

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(StartPoint(GeomFromText(@ls)));
    +---------------------------------------+
    | AsText(StartPoint(GeomFromText(@ls))) |
    +---------------------------------------+
    | POINT(1 1)                            |
    +---------------------------------------+

User Comments
Sign Up Login You must be logged in to post a comment.