topojson / topojson-client

Manipulate TopoJSON, such as to merge shapes, and convert it back to GeoJSON.
ISC License
213 stars 63 forks source link

Resultant merged polygon is malformed GeoJSON #14

Closed hackergrrl closed 7 years ago

hackergrrl commented 7 years ago

This gist reproduces the issue: https://gist.github.com/noffle/aad0b1db44a2e443b8c64897897064d0

There are three large Polygons, which produce a MultiPolygon when merged. However, each LinearRing inside does not repeat the first coordinates as the last coordinates as per the GeoJSON spec. This issue doesn't seem to appear with all merges, just this particular case. I notice that if I remove the 3rd polygon, this issue is no longer reproduced.

gmaclennan commented 7 years ago

This looks like this is caused by incorrect winding order on the input geojson. Rewinding the input geometry before merging results in correct output. It seems like topojson is picky about GeoJSON being valid, fair enough. FYI geojson-rewind does not currently rewind GeometryCollections https://github.com/mapbox/geojson-rewind/pull/14

hackergrrl commented 7 years ago

Great find, @gmaclennan!