PostGISGeometry Editors

ST_CollectionHomogenize

What is ST_CollectionHomogenize?

ST_CollectionHomogenize returns the "simplest" geometry equivalent to a given GeometryCollection. If every member is of the same type it returns a MULTI* (or a bare single geometry when only one component is present). Mixed-type collections are returned as collections but with nested sub-collections flattened.

SQL
ST_CollectionHomogenize(geometry collection)geometry

The function never discards components — it only restructures. Use it to normalize untrusted input before validation, indexing, or serialization.

When would you use ST_CollectionHomogenize?

Use ST_CollectionHomogenize when ingesting data from sources that over-wrap single features in GEOMETRYCOLLECTION(...) wrappers — some GML and KML exporters do this. Homogenizing before insertion prevents unnecessary complexity in the geometry column and may allow a tighter CHECK (GeometryType(geom) = 'POLYGON') constraint to pass.

It is also useful when chaining overlay operations, since it lets downstream code assume the simplest equivalent type without defensive CASE expressions on geometry type.

FAQs

Does ST_CollectionHomogenize remove any components?

No. It only restructures — a one-element collection becomes its sole member, and nested collections are flattened. All vertex data is preserved.

How is it different from ST_CollectionExtract?

ST_CollectionExtract selects components of one specific type and drops the rest. ST_CollectionHomogenize keeps every component but returns the simplest type that can represent them.

Will it convert MULTIPOLYGON to POLYGON when only one polygon is present?

Yes. A MULTIPOLYGON with a single ring is simplified to POLYGON. Be aware that this may break table constraints expecting MULTIPOLYGON — re-wrap with ST_Multi if needed.

Does it validate geometry?

No. ST_CollectionHomogenize only restructures — it does not repair self-intersections, invalid rings, or other validity issues. Pair it with ST_MakeValid if validity is a concern.