ST_LineString
If the geometry-expression is of type ST_LineString, return the geometry-expression. If the geometry-expression is of type ST_CircularString or ST_CompoundCurve, return geometry-expression.ST_CurveToLine(). If the geometry-expression is a geometry collection with a single element of type ST_Curve, return that element cast as ST_LineString. If the geometry-expression is the empty set, return an empty set of type ST_LineString. Otherwise, raise an exception condition.
The spatial reference system identifier of the result is the same as the spatial reference system of the geometry-expression.
Converts the geometry to a linestring. The logic is equivalent to that used for CAST( geometry-expression AS ST_LineString ). If the geometry-expression is a circularstring or compound curve, it is interpolated using ST_CurveToLine().
If geometry-expression is already known to be an ST_LineString value, it is more efficient to use TREAT( geometry-expression AS ST_LineString ) than the ST_ToLineString method.
Note
By default, ST_ToLineString uses the original format for a geometry, if it is available. Otherwise, the internal format is
used. For more information about internal and original formats, see STORAGE FORMAT clause, CREATE SPATIAL REFERENCE SYSTEM statement.
The following returns an error because the Shape column is of type ST_Geometry and ST_Geometry does not support the ST_Length
method.
SELECT Shape.ST_Length()
FROM SpatialShapes WHERE ShapeID = 5
The following uses ST_ToLineString to change the type of the Shape column expression to ST_LineString. ST_Length returns the
result 7.
SELECT Shape.ST_ToLineString().ST_Length()
FROM SpatialShapes WHERE ShapeID = 5
In this case, the value of the Shape column is known be of type ST_LineString, so TREAT can be used to efficiently change
the type of the expression. ST_Length returns the result 7.
SELECT TREAT( Shape AS ST_LineString ).ST_Length()
FROM SpatialShapes WHERE ShapeID = 5