The ST_LineFromGML() function

The ST_LineFromGML() function takes a GML2 or GML3 string representation of an ST_LineString and an optional spatial reference ID and returns a polyline object.

Syntax

ST_LineFromGML(gmlstring lvarchar)
ST_LineFromGML(gmlstring lvarchar, SRID integer)

Return type

ST_LineString

Example

The gml_linetest table is created with the SMALLINT column gid and the ST_LineString column ln1:
CREATE TABLE gml_linetest (gid smallint, ln1 ST_LineString);

INSERT INTO gml_linetest VALUES (1, ST_LineFromGML('<gml:LineString>
                <gml:posList> -110.45 45.256 -109.48 46.46 -109.86 43.84
                </gml:posList></gml:LineString>',4));
INSERT INTO gml_linetest VALUES (2, ST_LineFromGML('<gml:LineString 
                srsName="EPSG:4326" srsDimension="3"><gml:posList 
                dimension="3">-110.449999933 45.2559999343 10 
                -109.47999994 46.4600005499 10 -109.86000008 
                43.8400000201 20</gml:posList></gml:LineString>'));
INSERT INTO gml_linetest VALUES(3,ST_LineFromGML('<gml:LineString 
                srsName="EPSG:4326" srsDimension="4"><gml:posList 
                dimension="4">-110.449999933 45.2559999343 10  54 
                -109.47999994 46.4600005499 10  58 
                -109.86000008 43.8400000201 20 64 </gml:posList>
                </gml:LineString>'));

The first record specifies a spatial reference ID of 4 (WGS84) and a default dimension of 2. The second and third records contain Z and M measures and pass the spatial reference ID through the srsName attribute.

Output:
SELECT * FROM gml_linetest;

gid  1
ln1  4 LINESTRING (-110.449999933 45.2559999343, 
                   -109.47999994 46.4600000469, 
                   -109.86000008 43.8400000201)

gid  2
ln1  4 LINESTRING Z (-110.449999933 45.2559999343 10, 
                     -109.47999994 46.4600005499 10, 
                     -109.86000008 43.8400000201 20)

gid  3
ln1  4 LINESTRING ZM (-110.449999933 45.2559999343 10 54, 
                      -109.47999994 46.4600005499 10 58, 
                      -109.86000008 43.8400000201 20 64)