ST_CollectionExtract¶
Introduction: Returns a homogeneous multi-geometry from a given geometry collection.
The type numbers are:
- POINT
- LINESTRING
- POLYGON
If the type parameter is omitted a multi-geometry of the highest dimension is returned.
Format:
ST_CollectionExtract (A: Geometry)
ST_CollectionExtract (A: Geometry, type: Integer)
Since: v1.5.0
Example:
WITH test_data as (
ST_GeomFromText(
'GEOMETRYCOLLECTION(POINT(40 10), POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)))'
) as geom
)
SELECT ST_CollectionExtract(geom) as c1, ST_CollectionExtract(geom, 1) as c2
FROM test_data
Result:
+----------------------------------------------------------------------------+
|c1 |c2 |
+----------------------------------------------------------------------------+
|MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0))) |MULTIPOINT(40 10) | |
+----------------------------------------------------------------------------+