PostGISGeometry Validation

ST_MakeValid

What is ST_MakeValid?

ST_MakeValid attempts to return a valid OGC geometry equivalent to the input. Self-intersecting polygons are split into multi-polygons, nearly duplicate vertices merged, and other common validity issues resolved without discarding vertex information.

SQL
1ST_MakeValid(geometry geom)geometry
2ST_MakeValid(geometry geom, text params)geometry

The two-argument form (PostGIS 3.2+) accepts params such as 'method=structure keepcollapsed=true' to control the repair strategy.

When would you use ST_MakeValid?

Use ST_MakeValid to salvage invalid polygons before they reach overlay operations that would otherwise fail — unions of parcel data, intersections with land-use layers, or symmetric differences across change snapshots. Running ST_MakeValid first is cheaper than debugging mysterious overlay failures.

It is also useful after heavy geometry rewriting — ST_SnapToGrid, ST_Simplify, or aggressive ST_Buffer with negative distances can introduce self-intersections that ST_MakeValid then cleans up.

FAQs

Does ST_MakeValid change geometry type?

Possibly. A self-intersecting polygon often becomes a MULTIPOLYGON, and a bow-tie polygon may become a MULTIPOLYGON with two parts plus an isolated point. Handle with ST_CollectionExtract(geom, 3) if you need polygons only.

What params are available in PostGIS 3.2+?

method = linework (default, legacy) or structure (newer, faster, preserves structure better). keepcollapsed controls whether zero-area collapsed components are retained.

Can it introduce new vertices?

Yes. Intersections between rings are introduced as new vertices to split self-intersections.

What's the difference between ST_MakeValid and ST_Buffer(geom, 0)?

ST_Buffer(geom, 0) is a legacy trick that sometimes repairs invalid polygons but silently discards vertex information and can produce unexpected results. ST_MakeValid is purpose-built, deterministic, and preserves more of the original geometry.