mapbox/geojsonhint

validate polygon geometry

Opened this issue · 3 comments

It would be very useful to have a mode, perhaps not the default, that validates polygon geometry.

  • Winding order
  • No self-intersection
  • No holes intersecting/outside the outer ring

The validation should be at least strong enough to guarantee that any passing polygon is suitable for processing by geojson-vt. Then we could check incoming bug reports like mapbox/mapbox-gl-js#3074, mapbox/mapbox-gl-js#3032, and mapbox/mapbox-gl-js#3080 against it, point the submitters to geojsonhint when their data turns out to be invalid, and perhaps even embed it in mapbox-gl-js as a GeoJSON source preflight mechanism.

cc @tmcw @mourner @lucaswoj @springmeyer @mapsam

Winding order is only important for multipolygons in vector tiles, it shouldn't affect geojson-vt otherwise. Invalid intersections checks are pretty expensive, so we probably shouldn't embed the check in mapbox-gl-js. Also, since the GeoJSON spec doesn't dictate polygon validity, ideally we should clean up invalid polygons in geojson-vt rather than imposing requirements — that's just an extremely challenging computational geometry task that is a long way to go, but will be done eventually since we need it anyway (because polygons can become invalid through simplification).

tmcw commented

Yep, definitely support this. I'm not sure offhand how much code this would require; my suspicion is it'd be pretty significant, and might motivate this as a separate module or a separate require-path.

@mourner in geojson-vt we have control, but I've encountered enough implementations of GIS-ish operations that don't tolerate self-intersections etc that I think a utility would be useful, and much less work + code change than fixing all those implementations.