ST_LineString data type

The ST_LineString data type is a one-dimensional object stored as a sequence of points defining a linear interpolated path. ST_LineString types are often used to define linear features such as roads, rivers, and power lines.

Properties

An ST_LineString is simple if it does not intersect its interior. The endpoints (the boundary) of a closed ST_LineString occupy the same point in space. An ST_LineString is a ring if it is both closed and simple. In addition to properties inherited from the superclass ST_Geometry, ST_LineString values have length.

The endpoints normally form the boundary of a ST_LineString unless the ST_LineString is closed, in which case the boundary is NULL. The interior of a ST_LineString is the connected path that lies between the endpoints, unless it is closed, in which case the interior is continuous. The following figure shows examples of ST_LineString objects: (1) is a simple nonclosed ST_LineString; (2) is a nonsimple nonclosed ST_LineString; (3) is a closed simple ST_LineString and therefore is a ring; (4) is a closed nonsimple ST_LineString—it is not a ring.
Figure 1: Examples of ST_LineString objects

(1) is a line string that does not intersect itself. (2) is a line string that intersects itself at one point. (3) is a polygon. (4) is a line string that creates two polygons that are connects at one point.

Functions

The following functions operate on ST_LineString:
ST_StartPoint()
The function returns the linestring's first point.
ST_EndPoint()
The function returns the linestring's last point.
ST_PointN()
The function takes an ST_LineString and an index to nth point and returns that point.
ST_Length()
The function returns the linestring's length as a double-precision number.
ST_NumPoints()
The function returns the number of points in the linestring's sequence as an integer.
ST_IsRing()
The function returns t (TRUE) if the ST_LineString is a ring and f (FALSE) otherwise.
ST_IsClosed()
The function returns t (TRUE) if the ST_LineString is closed and f (FALSE) otherwise.
ST_Polygon()
The function creates a polygon from an ST_LineString that is a ring.