Name

ST_MakeGeomColl — Constructs a GeometryCollection object from a set of Geometries.

Synopsis

PostgreSQL

geometry ST_MakeGeomColl(bytea Geometry_Array);

geometry ST_MakeGeomColl(bytea Geometry_Aggregate);

H2

geometry ST_MakeGeomColl(bytea Geometry_Array);

geometry ST_MakeGeomCollAgg(bytea Geometry_Aggregate);

Alias

MakeGeomColl

Description

Constructs a GeometryCollection object from a set of Geometries. The method can take as input argument either a Geometry Array or a set of Geometries.

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

Array

PostgreSQL

select asewkt(MakeGeomColl(Array[ST_MakePoint(0, 0), ST_MakePoint(10, 10),ST_MakePoint(15, 10)]));
--Result
                             asewkt
----------------------------------------------------------------
 GEOMETRYCOLLECTION (POINT (0 0), POINT (10 10), POINT (15 10))
(1 row)



SELECT asewkt(ST_MakeGeomColl(
Array[
       ST_GeomFromText('POINT(0 0 10)'), 
       ST_GeomFromText('LINESTRING(0 0 10, 10 10 10)'),
       ST_GeomFromText('POLYGON ((2 1, 2 5, 6 5, 6 1, 2 1))')
]));

--Result
                        asewkt                                                      
------------------------------------------------------------------------
 GEOMETRYCOLLECTION (POINT (0 0 10), LINESTRING (0 0 10, 10 10 10), 
POLYGON ((2 1 0, 2 5 0, 6 5 0, 6 1 0, 2 1 0)))
(1 row)

H2

SELECT ST_AsText(ST_MakeGeomColl(st_accumagg(geom))) as geomcollect from (select array_get(
(
st_geomfromtext('POINT(0 0)'),
st_geomfromtext('POINT(10 10)'),
st_geomfromtext('POINT(15 15)')
),x)::binary as geom from (select x from system_range(1,3) as foo) as table);

--Result
GEOMCOLLECT  
GEOMETRYCOLLECTION (POINT (0 0), POINT (10 10), POINT (15 15))
Aggregate
create table "points"(id serial PRIMARY KEY);
SELECT AddGeometryColumn ('points','GEOM',25830,'POINT',2);
INSERT INTO "points" ("GEOM") VALUES (ST_GeomfromEWKT('SRID=25830;POINT (1 1)'));
INSERT INTO "points" ("GEOM") VALUES (ST_GeomfromEWKT('SRID=25830;POINT (1 7)'));
INSERT INTO "points" ("GEOM") VALUES (ST_GeomfromEWKT('SRID=25830;POINT (6 7)'));

--PostgreSQL
SELECT ST_AsEWKT(ST_MakeGeomColl("points"."GEOM")) from "points";

--H2
SELECT ST_AsEWKT(ST_MakeGeomCollAgg("points"."GEOM")) from "points";

--Result
SRID=25830;GEOMETRYCOLLECTION (POINT (1 1), POINT (1 7), POINT (6 7))

Related functions

ST_Collect, ST_Force_Collection