topojson / topojson-server

Convert GeoJSON to TopoJSON.
ISC License
117 stars 32 forks source link

topology generated incorrectly for shapes with holes that contain loops #25

Open terrencecrowley opened 3 years ago

terrencecrowley commented 3 years ago

In processing and simplifying census shapes, we ended up creating shapes that have a specific characteristic that appears to be handled incorrectly by the code that converts shapes to topology. The attached file demonstrates the issue (.txt ending for github).

Essentially, one shape contains a hole that ends up touching itself at a single point - it is essentially two holes that share a single point but described with a single ring in the polygon structure. All other processing is fine with this structure. The other shape is a multi-polygon that contains two separate polygons that fill the holes.

When converting these two shapes to a topology, the arcs that are part of the holes are treated as "lines" during the dedup process and therefore do not end up matching the "rings" that describe the polygons. The result is that there are two separate arcs describing the same series of points.

During merge process (in topojson-client), the result of the merge is a multi-polygon that includes the holes and the polygons that fill them because the arcs are not recognized as shared.

We have a forked version (in @dra2020/topojson-server) that implements a fix that works for us. Essentially at the point where dedupLine is going to be called, we first check if the start and end points of the line are the same and instead call dedupRing.

twoshapes.geojson.txt