ST_ToGeomColl function

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

If the specified geometry is empty, then it can be of any type. However, it is then converted to ST_Multipoint, ST_MultiLineString, or ST_MultiPolygon as appropriate.

If the specified geometry is not empty, then it must be of type ST_Point, ST_LineString, or ST_Polygon. These are then converted to ST_Multipoint, ST_MultiLineString, or ST_MultiPolygon respectively.

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_ToGeomColl(geometry)

Parameter

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

Return type

db2gse.ST_GeomCollection

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_ToGeomColl 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_Polygon ('polygon ((3 3, 4 6, 5 3, 3 3))', 1)),
         (2, ST_Point ('point (1 2)', 1))
In the following SELECT statement, the ST_ToGeomColl function is used to return geometries as their corresponding geometry collection subtypes.

SELECT id, CAST( ST_AsText( ST_ToGeomColl(geometry) ) 
    AS VARCHAR(120) ) GEOM_COLL
FROM sample_geometries
Results:

ID          GEOM_COLL
----------- ------------------------------------------------------
          1 MULTIPOLYGON ((( 3.00000000 3.00000000, 5.00000000 
                             3.00000000, 4.00000000 6.00000000, 
                             3.00000000 3.00000000)))
          2 MULTIPOINT ( 1.00000000 2.00000000)