ST_GeometryN — Returns the Nth geometry object in a Collection.
geometry ST_GeometryN(
varchar WKT, integer
SRID)
;
Returns the Nth geometry object in a Collection. The incoming geometry shall be a collection type like MULTIPOINT, MULTILINESTRING, MULTIPOLYGON or GEOMETRYCOLLECTION. Otherwise, returns NULL.
N index starts at 1. If N is less than one or greater than the cardinality of the Interior Rings attribute, then the function returns Null.
2D | 3D | M |
---|---|---|
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 |
---|---|---|---|
2.1.2.1 | 7.2.16.1 | 7.2.15 | 9.1.5 |
--Return the 1st geometry SELECT ST_AsEWKT( GeometryN( ST_GeomFromText('GEOMETRYCOLLECTION(POINT (5 5 10),LINESTRING (0 0 10, 0 50 10))'),1 )); --Result POINT (5 5 10) ----Return the 3rd point SELECT ST_AsEWKT( GeometryN( ST_GeomFromText('MULTIPOINT ((2 1), (1 2), (4 4), (2 4), (5 1))'),3 )); --Result POINT (4 4)