PostGIS
Synopsis
geometry +`*`+ST_MakeValid
*(`geometry `input`
)`;
geometry +`*`+ST_MakeValid
*(`geometry `input
, text
params`
)`;
Description
The function attempts to create a valid representation of a given invalid geometry without losing any of the input vertices. Valid geometries are returned unchanged.
Supported inputs are: POINTS, MULTIPOINTS, LINESTRINGS, MULTILINESTRINGS, POLYGONS, MULTIPOLYGONS and GEOMETRYCOLLECTIONS containing any mix of them.
In case of full or partial dimensional collapses, the output geometry may be a collection of lower-to-equal dimension geometries, or a geometry of lower dimension.
Single polygons may become multi-geometries in case of self-intersections.
The params
argument can be used to supply an options string to
select the method to use for building valid geometry. The options string
is in the format "method=linework|structure keepcollapsed=true|false".
If no "params" argument is provided, the "linework" algorithm will be
used as the default.
The "method" key has two values.
-
"linework" is the original algorithm, and builds valid geometries by first extracting all lines, noding that linework together, then building a value output from the linework.
-
"structure" is an algorithm that distinguishes between interior and exterior rings, building new geometry by unioning exterior rings, and then differencing all interior rings.
The "keepcollapsed" key is only valid for the "structure" algorithm, and takes a value of "true" or "false". When set to "false", geometry components that collapse to a lower dimensionality, for example a one-point linestring would be dropped.
Performed by the GEOS module.
Availability: 2.0.0
Enhanced: 2.0.1, speed improvements
Enhanced: 2.1.0, added support for GEOMETRYCOLLECTION and MULTIPOINT.
Enhanced: 3.1.0, added removal of Coordinates with NaN values.
Enhanced: 3.2.0, added algorithm options, 'linework' and 'structure' which requires GEOS >= 3.10.0.
This function supports 3d and will not drop the z-index.
Examples
before_geom: MULTIPOLYGON of 2 overlapping polygons
after_geom: MULTIPOLYGON of 4 non-overlapping polygons
after_geom_structure: MULTIPOLYGON of 1 non-overlapping polygon
|
before_geom: MULTIPOLYGON of 6 overlapping polygons
after_geom: MULTIPOLYGON of 14 Non-overlapping polygons
after_geom_structure: MULTIPOLYGON of 1 Non-overlapping polygon
|
Examples
SELECT ST_AsText(ST_MakeValid(
'LINESTRING(0 0, 0 0)',
'method=structure keepcollapsed=true'
));
st_astext
------------
POINT(0 0)
SELECT ST_AsText(ST_MakeValid(
'LINESTRING(0 0, 0 0)',
'method=structure keepcollapsed=false'
));
st_astext
------------------
LINESTRING EMPTY