d3 / d3-geo-projection

Extended geographic projections for d3-geo.
https://observablehq.com/collection/@d3/d3-geo-projection
Other
1.1k stars 201 forks source link

geoProject converts hole to MultiPolygon #201

Open ondras opened 3 years ago

ondras commented 3 years ago

As shown here: https://observablehq.com/@ondras/d3-geoproject-problem (resulting MultiPolygon has two distinct exterior-only polygons)

The simple GeoJSON feature is a triangle-shaped polygon with a smaller triangle-shaped hole. The problem is caused by a vertex that is shared between the hole and the outer boundary.

For comparison, the feature_good has the hole's problematic vertex shifted a tiny bit away from the exterior (towards the center) - and the geoProject call correctly preserves the hole.

Fil commented 3 years ago

I believe(d) this is considered "degenerate" in GeoJSON (but I admit I haven't been able to find a source).

However there is necessarily a discontinuity: if you allow that coordinate 47 to vary continuously as 47+x, it will go from "Polygon" for x < 0 to "MultiPolygon" for x > 0.

ondras commented 3 years ago

However there is necessarily a discontinuity:

I am okay with a discontinuity. I would just like to receive a "Polygon" for x==0.

Alternatively, this particular case can also return one polygon (five vertices, six edges), removing the hole from the exterior polygon (and using the problematic vertex twice). I suppose this would work as well.