ST_MakeValid¶
Introduction: Given an invalid geometry, create a valid representation of the geometry.
Collapsed geometries are either converted to empty (keepCollapsed=false) or a valid geometry of lower dimension (keepCollapsed=true). Default is keepCollapsed=false.
Vertex order and ring orientation
ST_MakeValid may reorder coordinates or reverse polygon ring orientation, including for already-valid inputs.
To enforce a specific orientation after repair, use ST_ForcePolygonCCW or ST_ForcePolygonCW, for example ST_ForcePolygonCCW(ST_MakeValid(geom)).
These functions enforce ring orientation; they are not guaranteed to restore the original vertex order or starting vertex.
Format:
ST_MakeValid (A: Geometry)
ST_MakeValid (A: Geometry, keepCollapsed: Boolean)
Return type: Geometry
Since: v1.5.0
Example:
WITH linestring AS (
SELECT ST_GeomFromWKT('LINESTRING(1 1, 1 1)') AS geom
) SELECT ST_MakeValid(geom), ST_MakeValid(geom, true) FROM linestring
Result:
+------------------+------------------------+
|st_makevalid(geom)|st_makevalid(geom, true)|
+------------------+------------------------+
| LINESTRING EMPTY| POINT (1 1)|
+------------------+------------------------+