This topic describes the ST_CollectionExtract function. This function returns one or multiple geometry objects of specified types from an input GeometryCollection object.
Syntax
geometry ST_CollectionExtract(geometry collection , integer type);
Parameters
Parameter | Description |
---|---|
collection | The geometry object that you want to specify. |
type | This function supports objects of the following types:
|
Description
- This function supports point objects, LineString objects, and polygon objects.
- If geometry objects of the specified types are not found in the input Geometrycollection object, an empty geometry object is returned.
- If you specify the type parameter to Polygon, the ST_CollectionExtract function returns a MultiPolygon object even when the edges of objects in the input GeometryCollection object are shared.
Note In most cases, the ST_CollectionExtract function returns an invalid MultiPolygon object.
For example, when you apply this function to a collection that is returned by the
ST_Split function, the ST_CollectionExtract function returns an invalid MultiPolygon
object.
Examples
SELECT ST_AsText(ST_CollectionExtract(ST_GeomFromText('GEOMETRYCOLLECTION(LINESTRING(1 1,2 1),LINESTRING(2 1,2 2))'),2));
st_astext
--------------------------------------
MULTILINESTRING((1 1,2 1),(2 1,2 2))
(1 row)