Name

ST_Extract — Extracts a particular type of geometry from a collection and converts them to MULTI*. The values for the type of geometry are 0=Point, 1=Line, 2=Polygon.

Synopsis

geometry ST_Extract(bytea Geometry, integer geomDimension);

Alias

Extract

Description

Extracts a particular type of geometry from a collection and converts them to MULTI*. The values for geomDimension are 0=Point, 1=Line, 2=Polygon

It is similar to applying ST_Dump and then ST_Collect.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

SELECT ST_AsText(ST_Extract(ST_GeomFromText('MULTIPOINT ((1 1), (2 3), (4 1))'),0));
--Result
MULTIPOINT ((1 1), (2 3), (4 1))

SELECT ST_AsText(ST_Extract(ST_GeomFromText(
 'GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(LINESTRING (0 0 15, 10 10 25, 20 10 35),POINT(0 0 10)))'
  ),1));
--Result
MULTILINESTRING ((0 0 15, 10 10 25, 20 10 35))

SELECT ST_AsText(ST_Extract(ST_GeomFromText(
 'GEOMETRYCOLLECTION(POLYGON ((0 0 1 1, 10 10 2 2, 10 0 3 3, 0 0 4 4)),POINT(0 0 0 0))'),2));
--Result
MULTIPOLYGON (((0 0 1 1, 10 10 2 2, 10 0 3 3, 0 0 4 4)))

Related functions

ST_Dump,ST_Collect,ST_Dimension,ST_CollectionExtract