14.16.7.3 LineString and MultiLineString Property Functions (original) (raw)

14.16.7.3 LineString and MultiLineString Property Functions

A LineString consists ofPoint 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 forMultiLineString values.

Unless otherwise specified, functions in this section handle their geometry arguments as follows:

These functions are available for obtaining linestring properties:

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