ST_LineString function
The ST_LineString function constructs a linestring from specified input.
- Well-known text (WKT) format
- Well-known binary (WKB) format
- ESRI shape format
- GeoJSON format
- Geography Markup Language (GML) format
A spatial reference system identifier can be provided optionally to identify the spatial reference system that the resulting linestring is in.
If the specified format is null, then null is returned.
For details about the supported formats, see Supported data formats.
Syntax
Parameters
- wkt
- A value of type VARCHAR or CLOB(2G) that contains the WKT format of the resulting linestring.
- wkb
- A value of type VARBINARY or BLOB(2G) that contains the WKB format of the resulting linestring.
- shape
- A value of type VARBiNARY or BLOB(2G) that represents the ESRI shape format of the resulting linestring.
- geojson
- A value of type VARCHAR or CLOB(2G) that represents the resulting linestring using GeoJSON.
- gml
- A value of type VARCHAR or CLOB(2G) that represents the resulting linestring using the Geography Markup Language (GML).
- srs_id
- A value of type INTEGER that identifies the spatial reference system for the resulting
linestring.
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 error is returned (SQLSTATE 38SU1).
Return type
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.
The following code uses the ST_LineString function to create and insert a line from a well-known text (WKT) line representation or from a well-known binary (WKB) format.The following code uses the ST_LineString function to create and insert a line from a well-known text (WKT) line representation, a geographic markup language (GML), or a GeoJSON format.
CREATE TABLE sample_lines(id SMALLINT, geometry ST_LineString)
INSERT INTO sample_lines(id, geometry)
VALUES
(1110, ST_LineString('linestring(850 250, 850 850)', 1)),
(1111, ST_LineString('<gml:LineString srsName="EPSG:4269"><gml:coord>
<gml:X>90</gml:X><gml:Y>90</gml:Y>
</gml:coord><gml:coord><gml:X>100</gml:X>
<gml:Y>100</gml:Y></gml:coord>
</gml:LineString>', 1))
SELECT id, cast(ST_AsText(geometry) AS varchar(75)) AS linestring
FROM sample_lines
CREATE TABLE sample_lines(id SMALLINT, geometry ST_LineString)
INSERT INTO sample_lines(id, geometry)
VALUES
(1110, ST_LineString('linestring(850 250, 850 850)')),
(1111, ST_LineString('<gml:LineString srsName="EPSG:4326"><gml:coord>
<gml:X>90</gml:X><gml:Y>90</gml:Y>
</gml:coord><gml:coord><gml:X>100</gml:X>
<gml:Y>100</gml:Y></gml:coord>
</gml:LineString>')),
(1112, ST_LineString('{ "type": "Linestring", "coordinates":
[[10.0, 11.2], [10.5, 11.9]] }'))
SELECT id, cast(ST_AsText(geometry) AS varchar(75)) AS linestring
FROM sample_lines
Results:
ID LINESTRING
------ ------------------------------------------------------------------
1110 LINESTRING (850.000000 250.000000, 850.000000 850.000000)
1111 LINESTRING (90.000000 90.000000, 100.000000 100.000000)
ID LINESTRING
------ ------------------------------------------------------------------
1110 LINESTRING (850.000000 250.000000, 850.000000 850.000000)
1111 LINESTRING (90.000000 90.000000, 100.000000 100.000000)
1112 LINESTRING (10.000000000 11.200000000, 10.500000000 11.900000000)