LineString 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.
EndPoint(ls)Returns the
Pointthat is the endpoint of theLineStringvaluels.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 as a double-precision number the length of the
LineStringvaluelsin its associated spatial reference.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';mysql>SELECT GLength(GeomFromText(@ls));+----------------------------+ | GLength(GeomFromText(@ls)) | +----------------------------+ | 2.8284271247462 | +----------------------------+GLength()is a nonstandard name. It corresponds to the OpenGISLength()function.NumPoints(ls)Returns the number of
Pointobjects in theLineStringvaluels.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-thPointin theLinestringvaluels. Points are numbered beginning with 1.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
Pointthat is the start point of theLineStringvaluels.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';mysql>SELECT AsText(StartPoint(GeomFromText(@ls)));+---------------------------------------+ | AsText(StartPoint(GeomFromText(@ls))) | +---------------------------------------+ | POINT(1 1) | +---------------------------------------+
The OpenGIS specification also defines the following function, which MariaDB does not implement:
IsRing(ls)Returns 1 if the
LineStringvaluelsis closed (that is, itsStartPoint()andEndPoint()values are the same) and is simple (does not pass through the same point more than once). Returns 0 iflsis not a ring, and -1 if it isNULL.