Skip to content
🎉 Apache Sedona 1.8.1 is now available! Check out the new features and improvements.

ST_Collect

Introduction:

Build an appropriate Geometry, MultiGeometry, or GeometryCollection to contain the Geometrys in it. For example:

  • If geomList contains a single Polygon, the Polygon is returned.
  • If geomList contains several Polygons, a MultiPolygon is returned.
  • If geomList contains some Polygons and some LineStrings, a GeometryCollection is returned.
  • If geomList is empty, an empty GeometryCollection is returned.

Note that this method does not "flatten" Geometries in the input, and hence if any MultiGeometries are contained in the input, a GeometryCollection containing them will be returned.

Format

ST_Collect(*geom: geometry)

Example:

WITH src_tbl AS (
    SELECT sedona.ST_GeomFromText('POINT (40 10)') AS geom
    UNION
    SELECT sedona.ST_GeomFromText('LINESTRING (0 5, 0 10)') AS geom
)
SELECT sedona.ST_AsText(collection)
FROM src_tbl,
     TABLE(sedona.ST_Collect(src_tbl.geom) OVER (PARTITION BY 1));

Result:

GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (0 5, 0 10))