ST_ToLineString function

The ST_ToLineString function takes a geometry as an input parameter and converts it to a linestring. The resulting linestring is represented in the spatial reference system of the given geometry.

The given geometry must be empty or a linestring. If the given geometry is null, then null is returned.

This function can also be called as a method.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_ToLineString(geometry)

Parameter

geometry
A value of type ST_Geometry or one of its subtypes that represents the geometry that is converted to a linestring.

A geometry can be converted to a linestring if it is empty or a linestring. If the conversion cannot be performed, then an exception condition is raised (SQLSTATE 38SUD).

Return type

db2gse.ST_LineString

Example

In the following example, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display

This example illustrates the use of the ST_ToLineString function.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geometries (id INTEGER, geometry ST_Geometry)

INSERT INTO sample_geometries
  VALUES (1, ST_Geometry ('linestring z (0 10 1, 0  0 3, 10 0 5)', 0)),
         (2, ST_Geometry ('point empty', 1) ),
         (3, ST_Geometry ('multipolygon empty', 1) )

In the following SELECT statement, the ST_ToLineString function is used to return linestrings converted to ST_LineString from the static type of ST_Geometry.

SELECT CAST( ST_AsText( ST_ToLineString(geometry) ) 
     AS VARCHAR(130) ) LINES
FROM sample_geometries
Results:

LINES
------------------------------------------------------------------
LINESTRING Z ( 0.00000000 10.00000000 1.00000000, 0.00000000
               0.00000000 3.00000000, 10.00000000 0.00000000 
               5.00000000)
LINESTRING EMPTY
LINESTRING EMPTY