ST_GeomCollFromTxt function

The ST_GeomCollFromTxt function takes a well-known text representation of a geometry collection and, optionally, a spatial reference system identifier as input parameters and returns the corresponding geometry collection.

If the given well-known text representation is null, then null is returned.

The recommended function for achieving the same result is ST_GeomCollection. It is recommended because of its flexibility: ST_GeomCollection takes additional forms of input as well as the well-known binary representation.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_GeomCollFromTxt(wkt,srs_id)

Parameter

wkt
A value of type CLOB(2G) that contains the well-known text representation of the resulting geometry collection.
srs_id
A value of type INTEGER that identifies the spatial reference system for the resulting geometry collection.

If the srs_id parameter is omitted, the spatial reference system with the numeric identifier 0 (zero) is used implicitly.

If srs_id does not identify a spatial reference system listed in the catalog view DB2GSE.ST_SPATIAL_REFERENCE_SYSTEMS, then an error is returned (SQLSTATE 38SU1).

Return type

db2gse.ST_GeomCollection

Example

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

The following code illustrates how the ST_GeomCollFromTxt function can be used to create and insert a multipoint, multiline, and multipolygon from a well-known text (WKT) representation into a GeomCollection column.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse 

CREATE TABLE sample_geomcollections(id INTEGER, geometry ST_GEOMCOLLECTION)

INSERT INTO sample_geomcollections(id, geometry)
VALUES
    (4011, ST_GeomCollFromTxt('multipoint(1 2, 4 3, 5 6)', 1) ),
    (4012, ST_GeomCollFromTxt('multilinestring(
                           (33 2, 34 3, 35 6),
                           (28 4, 29 5, 31 8, 43 12),
                           (39 3, 37 4, 36 7))', 1) ),
    (4013, ST_GeomCollFromTxt('multipolygon(((3 3, 4 6, 5 3, 3 3),
                           (8 24, 9 25, 1 28, 8 24),
                           (13 33, 7 36, 1 40, 10 43, 13 33)))', 1))

SELECT id, cast(geometry..ST_AsText AS varchar(340)) 
   AS geomcollection
FROM   sample_geomcollections

Results:

ID          GEOMCOLLECTION
----------- -----------------------------------------------------------------
4011        MULTIPOINT ( 1.00000000 2.00000000, 4.00000000 3.00000000, 
   5.00000000 6.00000000)                
                                                           
4012        MULTILINESTRING (( 33.00000000 2.00000000, 34.00000000 
   3.00000000, 35.00000000 6.00000000),( 28.00000000 4.00000000, 29.00000000
   5.00000000, 31.00000000 8.00000000, 43.00000000 12.00000000),( 39.00000000
   3.00000000, 37.00000000 4.00000000, 36.00000000 7.00000000))

4013        MULTIPOLYGON ((( 13.00000000 33.00000000, 10.00000000 43.00000000,
   1.00000000 40.00000000, 7.00000000 36.00000000, 13.00000000 33.00000000)),
   (( 8.00000000 24.00000000, 9.00000000 25.00000000, 1.00000000 28.00000000,
   8.00000000 24.00000000)),(( 3.00000000 3.00000000, 5.00000000 3.00000000,
   4.00000000 6.00000000, 3.00000000 3.00000000)))