You are on page 1of 2

PostGIS 1.5.

1 Manual
220 / 315

Description
Output type can be a MULTI* or a GEOMETRYCOLLECTION. Comes in 2 variants. Variant 1 collects 2 geometries. Variant
2 is an aggregate function that takes a set of geometries and collects them into a single ST_Geometry.
Aggregate version: This function returns a GEOMETRYCOLLECTION or a MULTI object from a set of geometries. The
ST_Collect() function is an "aggregate" function in the terminology of PostgreSQL. That means that it operates on rows of
data, in the same way the SUM() and AVG() functions do. For example, "SELECT ST_Collect(GEOM) FROM GEOMTABLE
GROUP BY ATTRCOLUMN" will return a separate GEOMETRYCOLLECTION for each distinct value of ATTRCOLUMN.
Non-Aggregate version: This function returns a geometry being a collection of two input geometries. Output type can be a
MULTI* or a GEOMETRYCOLLECTION.
Note
ST_Collect and ST_Union are often interchangeable. ST_Collect is in general orders of magnitude faster than
ST_Union because it does not try to dissolve boundaries or validate that a constructed MultiPolgon doesnt have overlapping regions. It merely rolls up single geometries into MULTI and MULTI or mixed geometry types into Geometry
Collections. Unfortunately geometry collections are not well-supported by GIS tools. To prevent ST_Collect from returning a Geometry Collection when collecting MULTI geometries, one can use the below trick that utilizes ST_Dump
to expand the MULTIs out to singles and then regroup them.

Availability: 1.4.0 - ST_Collect(geomarray) was introduced. ST_Collect was enhanced to handle more geometries faster.
This function supports 3d and will not drop the z-index.
This method supports Circular Strings and Curves This method supports Circular Strings and Curves, but will never return
a MULTICURVE or MULTI as one would expect and PostGIS does not currently support those.

Examples
Aggregate example
Thread ref: http://postgis.refractions.net/pipermail/postgis-users/2008-June/020331.html
SELECT stusps,
ST_Multi(ST_Collect(f.the_geom)) as singlegeom
FROM (SELECT stusps, (ST_Dump(the_geom)).geom As the_geom
FROM
somestatetable ) As f
GROUP BY stusps

Non-Aggregate example
Thread ref: http://postgis.refractions.net/pipermail/postgis-users/2008-June/020331.html
SELECT ST_AsText(ST_Collect(ST_GeomFromText(POINT(1 2)),
ST_GeomFromText(POINT(-2 3)) ));
st_astext
---------MULTIPOINT(1 2,-2 3)
--Collect 2 d points
SELECT ST_AsText(ST_Collect(ST_GeomFromText(POINT(1 2)),
ST_GeomFromText(POINT(1 2)) ) );
st_astext
---------MULTIPOINT(1 2,1 2)

PostGIS 1.5.1 Manual


221 / 315

--Collect 3d points
SELECT ST_AsEWKT(ST_Collect(ST_GeomFromEWKT(POINT(1 2 3)),
ST_GeomFromEWKT(POINT(1 2 4)) ) );
st_asewkt
------------------------MULTIPOINT(1 2 3,1 2 4)
--Example with curves
SELECT ST_AsText(ST_Collect(ST_GeomFromText(CIRCULARSTRING(220268 150415,220227 150505,220227 150406)),
ST_GeomFromText(CIRCULARSTRING(220227 150406,2220227 150407,220227 150406))));
st_astext
-----------------------------------------------------------------------------------GEOMETRYCOLLECTION(CIRCULARSTRING(220268 150415,220227 150505,220227 150406),
CIRCULARSTRING(220227 150406,2220227 150407,220227 150406))
--New ST_Collect array construct
SELECT ST_Collect(ARRAY(SELECT the_geom FROM sometable));
SELECT ST_AsText(ST_Collect(ARRAY[ST_GeomFromText(LINESTRING(1 2, 3 4)),
ST_GeomFromText(LINESTRING(3 4, 4 5))])) As wktcollect;
--wkt collect -MULTILINESTRING((1 2,3 4),(3 4,4 5))

See Also
ST_Dump, ST_Union

7.9.4 ST_ConvexHull
Name
ST_ConvexHull The convex hull of a geometry represents the minimum convex geometry that encloses all geometries within
the set.

Synopsis
geometry ST_ConvexHull(geometry geomA);

Description
The convex hull of a geometry represents the minimum convex geometry that encloses all geometries within the set.
One can think of the convex hull as the geometry you get by wrapping an elastic band around a set of geometries. This is different
from a concave hull (not currently supported) which is analogous to shrink-wrapping your geometries.
It is usually used with MULTI and Geometry Collections. Although it is not an aggregate - you can use it in conjunction with
ST_Collect to get the convex hull of a set of points. ST_ConvexHull(ST_Collect(somepointfield)).
It is often used to determine an affected area based on a set of point observations.
Performed by the GEOS module

You might also like