Geometry validation
Invalid geometries are a spatial analyst's nightmare. They can appear in any dataset, and can break a carefully-designed, long-running query in the middle of execution. Or even worse, a failing query might break an application's functionality. Luckily, PostGIS is equipped with the tools to find and repair them.
Simplicity and validity
In PostGIS, there are two concepts: simplicity and validity. For most spatial analyses to succeed, input geometries have to be both simple and valid. Here are some rules:
- Does not have repeated points (with the exception of closed rings, whose first and last point are identical)
- Does not self-intersect
- A point must always be simple and valid
- A MultiPoint must always be valid, and simple when there are no repeated points with identical coordinates
- A LineString or MultiLineString must always be valid, and is simple if the line:
Example of a non-simple line: self-intersecting autogenerated contours.
A polygon is always simple, and is valid if:
- All interior...