| 1 | = Geometry Cleaning = |
| 2 | |
| 3 | Cleaning is fundamentally a difficult problem, because things can be dirty in so many ways. Here's a list of cases that need to be addressed in any geometry cleaning routines. |
| 4 | |
| 5 | * POLYGON rings must not self-touch |
| 6 | * The classic "bow-tie" polygon would have to be re-written as a "polygon with hole that touches once" |
| 7 | * POLYGON rings should not have zero area |
| 8 | * POLYGONs should probably not have zero area |
| 9 | * POLYGON rings must be properly nested and only touch once |
| 10 | * POLYGONs with rings that touch along a segment should have the inner ring and zero-width corridor removed |
| 11 | * LINESTRINGs and POLYGON rings should not have duplicate vertices and probably not have vertices within a tolerance of one another |
| 12 | * For POLYGONs in a coverage, this will break edge-matching |
| 13 | * LINESTRINGs and POLYGON rings should probably not have "spikes" or "gores" |
| 14 | * These elements create two very parallel segments in the feature, which lead to topology failures later on |
| 15 | * MULTIPOLYGONS are not allowed to have parts that touch |
| 16 | * Fixing this in generality is hard because it requires dissolving which is itself a topologically sensitive operation |
| 17 | * POLYGON rings must not cross |
| 18 | |
| 19 | The potential for breaking edge-matching calls for a further cleaning function, that takes in two geometries and snaps the edges of one to another, within a tolerance. |
| 20 | |
| 21 | * ST_SnapToReference(referencegeometry, geometry, tolerance) |
| 22 | |
| 23 | A self-join could be used to run this function on all pairwise possibilities in a table to "complete the cleaning" of a coverage. |