A GEOMETRYCOLLECTION is a collection of heterogeneous spatial objects, such as Points, LineStrings, Polygons, or other GEOMETRYCOLLECTIONs. It provides a way of referring to a group of spatial objects as one "thing" so that you can operate on it/them more conveniently using various SQL functions.
New in v21.1:
You can also store a GEOMETRYCOLLECTION with the following additional dimensions:
- A third dimension coordinate
Z(GEOMETRYCOLLECTIONZ). - A measure coordinate
M(GEOMETRYCOLLECTIONM). - Both a third dimension and a measure coordinate (
GEOMETRYCOLLECTIONZM).
The Z and M dimensions can be accessed or modified using a number of built-in functions, including:
ST_ZST_MST_AffineST_ZmflagST_MakePointST_MakePointMST_Force3DST_Force3DZST_Force3DMST_Force4DST_SnapST_SnapToGridST_RotateZST_AddMeasure
Note that CockroachDB's spatial indexing is still based on the 2D coordinate system. This means that:
- The Z/M dimension is not index accelerated when using spatial predicates.
- Some spatial functions ignore the Z/M dimension, with transformations discarding the Z/M value.
Examples
A GeometryCollection can be created from SQL by calling the st_geomfromtext function on a GeometryCollection definition expressed in the Well Known Text (WKT) format as shown below.
SELECT ST_GeomFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0, 1440 900), POLYGON((0 0, 0 1024, 1024 1024, 1024 0, 0 0)))');
st_geomfromtext
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0107000000030000000101000000000000000000000000000000000000000102000000020000000000000000000000000000000000000000000000008096400000000000208C40010300000001000000050000000000000000000000000000000000000000000000000000000000000000009040000000000000904000000000000090400000000000009040000000000000000000000000000000000000000000000000
(1 row)