ST_Normalize
What is ST_Normalize?
ST_Normalize returns the "canonical" form of a geometry — ring vertices are reordered to start at the lexicographically smallest point, ring orientation is standardized, and sub-geometries within collections are sorted. Two geometries that are spatially equal but have different internal representations normalise to the same value.
ST_Normalize(geometry geom) → geometryThe output is bit-for-bit deterministic for a given spatial shape, enabling equality testing via byte-level comparison.
When would you use ST_Normalize?
Use ST_Normalize when checksumming geometry for change detection across snapshots — hashing the EWKB of normalised geometry gives a stable fingerprint that ignores cosmetic vertex ordering differences. It also makes UNIQUE constraints on geometry columns behave sensibly.
In deduplication pipelines, normalising before grouping collapses rows that describe the same polygon even when they were digitised by different people with different ring starts.
FAQs
Does ST_Normalize change the spatial shape?
No. It only reorders vertices and sub-geometries into a canonical form. ST_Equals returns true before and after.
Can I use ST_Normalize for deduplication?
Yes. SELECT DISTINCT ST_AsBinary(ST_Normalize(geom)) FROM ... removes duplicates that differ only by ring start or component order.
Is it a replacement for ST_Equals?
Not exactly. ST_Equals performs a spatial equality test (including tolerance-style boundary handling via GEOS). ST_Normalize produces a byte-equal result for the same spatial shape, which is much faster to compare in bulk.
Does it affect SRID?
No. SRID is preserved; only vertex and component ordering change.