ST_MakeValid — 尝试在不丢失顶点的情况下使无效几何体有效。
geometry ST_MakeValid(
geometry input)
;
geometry ST_MakeValid(
geometry input, text params)
;
该函数尝试创建给定无效几何体的有效表示,而不丢失任何输入顶点。 有效几何图形原封不动地返回。
相应的输入是点、多点、线串、多线串、多边形、多多边形、几何集合及其混合。
在完全或部分尺寸折叠的情况下,输出几何是相同或较低维度的几何集合,或者是较低维度几何的集合。
在自相交的情况下,单个多边形可能会变成多重几何图形。
params
参数可用于提供选项字符串来选择用于构建有效几何图形的方法。 选项字符串的格式为“method=linework|struct keepcollapsed=true|false”。 如果未提供“params”参数,则将使用“linework”算法作为默认值。
“method”键有两个值。
"linework" is the default algorithm, and builds valid geometries by first extracting all lines, noding that linework together, then building a value output from the linework. The requirement that no vertices are lost can generate complex collections as outputs.
"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 results tend to be more intuitive, where collapsed lines are discarded in the output.
The "keepcollapsed" key is only valid for the "structure" algorithm, and takes a value of "true" or "false".
Keep collapsed of "false" is the default, and means that geometry components that collapse to a lower dimensionality, for example a one-point linestring will be dropped.
Keep collapsed of "true" means geometry components that collapse to a lower dimensionality will be retained.
这个函数是由 GEOS 模块执行的。
可用性: 2.0.0
增强:2.0.1 速度提升
增强:2.1.0添加了对几何集合和多点的支持。
增强:3.1.0删除了具有NaN值的坐标。
增强:在 3.2.0 中,添加了可选的算法参数“linework”和“structure”。 需要 GEOS>= 3.10.0 或更高版本。
该函数支持 3d 并且不会丢失 z-index。
![]() before_geom:由两个重叠多边形组成的多多边形
![]() after_geom:具有四个非重叠多边形的多多边形
![]() after_geom_structure:由单个非重叠多边形组成的多多边形
SELECT f.geom AS before_geom, ST_MakeValid(f.geom) AS after_geom, ST_MakeValid(f.geom, 'method=structure') AS after_geom_structure FROM (SELECT 'MULTIPOLYGON(((186 194,187 194,188 195,189 195,190 195, 191 195,192 195,193 194,194 194,194 193,195 192,195 191, 195 190,195 189,195 188,194 187,194 186,14 6,13 6,12 5,11 5, 10 5,9 5,8 5,7 6,6 6,6 7,5 8,5 9,5 10,5 11,5 12,6 13,6 14,186 194)), ((150 90,149 80,146 71,142 62,135 55,128 48,119 44,110 41,100 40, 90 41,81 44,72 48,65 55,58 62,54 71,51 80,50 90,51 100, 54 109,58 118,65 125,72 132,81 136,90 139,100 140,110 139, 119 136,128 132,135 125,142 118,146 109,149 100,150 90)))'::geometry AS geom) AS f;
|
![]() before_geom:由六个重叠多边形组成的多多边形
![]() after_geom:由 14 个不重叠多边形组成的多多边形
![]() after_geom_structure:由单个非重叠多边形组成的多多边形
SELECT c.geom AS before_geom, ST_MakeValid(c.geom) AS after_geom, ST_MakeValid(c.geom, 'method=structure') AS after_geom_structure FROM (SELECT 'MULTIPOLYGON(((91 50,79 22,51 10,23 22,11 50,23 78,51 90,79 78,91 50)), ((91 100,79 72,51 60,23 72,11 100,23 128,51 140,79 128,91 100)), ((91 150,79 122,51 110,23 122,11 150,23 178,51 190,79 178,91 150)), ((141 50,129 22,101 10,73 22,61 50,73 78,101 90,129 78,141 50)), ((141 100,129 72,101 60,73 72,61 100,73 128,101 140,129 128,141 100)), ((141 150,129 122,101 110,73 122,61 150,73 178,101 190,129 178,141 150)))'::geometry AS geom) AS c;
|
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