Repairs an invalid geometry object without removing any vertices.
Syntax
geometry ST_MakeValid(geometry input);Parameters
| Parameter | Description |
|---|---|
input | The geometry object to repair. |
Behavior
Operates only on invalid geometry objects. Valid geometry objects are returned unchanged.
Supports the following geometry types: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, GeometryCollection, and combinations of these types.
If the input geometry object is missing dimensions in whole or in part, the function returns a geometry object of lower dimensionality, or a collection of lower-dimensional geometry objects.
If the input is a polygon with self-intersections, the function may return a MULTI object.
Examples
The following example repairs a self-intersecting polygon. Because the input polygon crosses itself, ST_MakeValid splits it into two non-overlapping polygons and returns a MULTIPOLYGON.
SELECT ST_AsText(ST_MakeValid('POLYGON((0 0,0 1,1 0,1 1,0 0))'));Output:
st_astext
----------------------------------------------------------------
MULTIPOLYGON(((0 0,0 1,0.5 0.5,0 0)),((0.5 0.5,1 1,1 0,0.5 0.5)))
(1 row)