Geometry processing functions
Spatial operation functions are used to perform various operations and transformations on spatial geometry objects, including shape modification, geometric relationship calculation, spatial queries, and other types of spatial analysis.
seekdb currently supports the _ST_MakeValid() function for geometry processing.
_ST_MakeValid
In a geographic information system (GIS), spatial data often needs to meet certain validity standards. A valid polygon should be simple (non-intersecting) and correctly oriented (clockwise for the outer ring, counterclockwise for the inner ring). Invalid polygons may contain geometric errors such as self-intersections, overlapping rings, or exposed holes.
The _ST_MakeValid function is used to fix invalid geometry (such as polygons) to make them valid. However, this function only supports projected coordinate systems and does not support geographic coordinate systems.
-
Supported: Projected coordinate systems. This function expects the input geometry to be in a projected coordinate system, not a geographic coordinate system. A projected coordinate system is a planar coordinate system where positions on the ground are represented by two coordinates.
-
Not supported: Geographic coordinate systems. Geographic coordinate systems are based on the Earth's latitude and longitude system, taking into account the Earth's curvature. The
_ST_MakeValidfunction does not support geographic coordinate systems, and the input geometry cannot be based on latitude and longitude coordinates.
The syntax is as follows:
_ST_MakeValid(geometry input)
Parameter description:
geometry input: This is the input parameter for the function, representing the geometry object to be fixed. It can be any type of geometry, such as a point (Point), line (LineString), or polygon (Polygon).
Here is an example:
select st_astext(_st_makevalid(st_geomfromtext('POLYGON((0 0,1 1,2 2,0 2,1 1,2 0,0 0))')));
In this example, st_geomfromtext('POLYGON((0 0,1 1,2 2,0 2,1 1,2 0,0 0))') converts the text-formatted polygon into a geometry object. The text string 'POLYGON((0 0,1 1,2 2,0 2,1 1,2 0,0 0))' represents a sequence of polygon vertices, but the polygon is invalid because it has self-intersecting vertices.
Then, the _st_makevalid(...) function fixes the invalid polygon geometry to make it valid.
Finally, st_astext(...) converts the fixed geometry back to its Well-Known Text (WKT) format.
The result is as follows:
+-------------------------------------------------------------------------------------+
| st_astext(_st_makevalid(st_geomfromtext('POLYGON((0 0,1 1,2 2,0 2,1 1,2 0,0 0))'))) |
+-------------------------------------------------------------------------------------+
| MULTIPOLYGON(((1 1,2 2,0 2,1 1)),((1 1,0 0,2 0,1 1))) |
+-------------------------------------------------------------------------------------+
1 row in set (0.001 sec)