Prevent segment intersections caused by coordinate rounding and quantization
mbloch opened this issue · 2 comments
Several of mapshaper's commands can shift coordinates so that intersections occur between line segments; for example, exporting with the precision
option, using the -snap
command, and exporting TopoJSON with quantization applied.
Datasets that contain intersections, especially self-intersections within a single feature, can cause problems when used with some popular software. PostGIS considers self-intersecting geometries to be invalid. Polygons with intersections can cause rendering artifacts in WebGL-based libraries like mapbox-gl-js.
There should be a way to round coordinates without introducing intersections.
I propose adding an optional parameter that checks for intersections after rounding has been applied, and replaces the endpoints of intersecting segments with original coordinates. This might have to be repeated several times until all intersections are removed.
In the case of TopoJSON, this process would introduce non-integer delta-encoded coordinates. The TopoJSON spec says that quantized coordinates are integers. My hunch is that most TopoJSON software libraries would accept decimal coordinates, but that's just a hunch.
+1000 for all the formats :)
You got it! v0.6.61 adds the fix-geometry
option to -snap
and -o
commands. This first implementation only removes segment intersections, it does not fix some other problems that rounding can cause, like spikes.