ST_MultiLineString function

The ST_MultiLineString function constructs a multilinestring from a specified input.

The input can be specified in one of the following formats:
  • Well-known text (WKT) format
  • Well-known binary (WKB) format
  • ESRI shape format
  • GeoJSON format
  • Geography Markup Language (GML) format

An optional spatial reference system identifier can be specified to identify the spatial reference system that the resulting multilinestring is in.

If the specified format is null, then null is returned.

For details about the supported formats, see Supported data formats.

Syntax

Read syntax diagramSkip visual syntax diagramST_MultiLineString( wktwkbshapegeojsongml,srs_id)

Parameters

wkt
A value of type VARCHAR or CLOB(2G) that contains the WKT format of the resulting multilinestring.
wkb
A value of type VARBINARY or BLOB(2G) that contains the WKB format of the resulting multilinestring.
shape
A value of type VARBINARY or BLOB(2G) that represents the ESRI shape format of the resulting multilinestring.
geojson
A value of type VARCHAR or CLOB(2G) that represents the resulting multilinestring using GeoJSON.
gml
A value of type VARCHAR or CLOB(2G) that represents the resulting multilinestring using the Geography Markup Language.
srs_id
A value of type INTEGER that identifies the spatial reference system for the resulting multilinestring.

If the srs_id parameter is omitted, then the spatial reference system with the numeric identifier 4326 is used.

If srs_id does not identify a spatial reference system listed in the catalog view SYSGEO.ST_SPATIAL_REFERENCE_SYSTEMS, then an exception condition is raised (SQLSTATE 38SU1).

Return type

ST_MultiLineString

Examples

Example 1:

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 how ST_MultiLineString can be used to create and insert a multilinestring from its WKT format. The record that is inserted has ID = 1110, and the geometry is a multilinestring in spatial reference system 1. The multilinestring is in the well-known text representation of a multilinestring. The X and Y coordinates for this geometry are:
  • Line 1: (33, 2) (34, 3) (35, 6)
  • Line 2: (28, 4) (29, 5) (31, 8) (43, 12)
  • Line 3: (39, 3) (37, 4) (36, 7)

CREATE TABLE sample_mlines (id INTEGER, geometry ST_MultiLineString)

INSERT INTO sample_mlines
  VALUES (1110,
          ST_MultiLineString ('multilinestring ( (33 2, 34 3, 35 6),
                                       (28 4, 29 5, 31 8, 43 12),
                                       (39 3, 37 4, 36 7) )', 1) )
The following SELECT statement returns the multilinestring that was recorded in the table:

SELECT id,
       CAST( ST_AsText( geometry ) AS VARCHAR(280) )
  MULTI_LINE_STRING
  FROM sample_mlines
  WHERE id = 1110
Results:

ID      MULTI_LINE_STRING
------  --------------------------------------------------------------------
  1110  MULTILINESTRING ((33.000000 2.000000, 34.000000 3.000000, 
                          35.000000 6.000000),
                         (28.000000 4.000000, 29.000000 5.000000, 
                          31.000000 8.000000, 43.000000 12.000000),
                         (39.000000 3.000000, 37.000000 4.000000, 
                          36.000000 7.000000))             
Example 2:
This example illustrates how ST_MultiLineString can be used to create and insert a multilinestring from its GeoJSON format. The record that is inserted has ID = 1111, and the geometry is a multilinestring in GeoJSON format and in spatial reference system 4326 explicitly set. Spatial reference system 4326 is also used if no SRSID is specified. The geometry data used is the same as in Example 1.

CREATE TABLE sample_mlines (id INTEGER, geometry ST_MultiLineString)

INSERT INTO sample_mlines
  VALUES (1111, ST_MultiLineString ('{ "type": "multilinestring", "coordinates": 
                                     [ [[33, 2], [34, 3], [35, 6]],
                                       [[28, 4], [29, 5], [31, 8], [43, 12]],
                                       [[39, 3], [37, 4], [36, 7]] 
                                     ] }', 4326) )
The following SELECT statement returns the multilinestring that was recorded in the table:

SELECT id,
       CAST( ST_AsText( geometry ) AS VARCHAR(400) )
  MULTI_LINE_STRING
  FROM sample_mlines
  WHERE id = 1111
Results:

ID      MULTI_LINE_STRING
------  --------------------------------------------------------------------
1111    MULTILINESTRING ((33.000000000 2.000000000, 34.000000000 3.000000000, 
                          35.000000000 6.000000000),(28.000000000 4.000000000, 
                          29.000000000 5.000000000, 31.000000000 8.000000000, 
                          43.000000000 12.000000000),(39.000000000 3.000000000, 
                          37.000000000 4.000000000, 36.000000000 7.000000000))