mask - option for islands in holes to be pulled out as separate MultiPolygon exterior rings
See original GitHub issueThe mask function takes an input
polygon and inverts it such all areas outside the input
polygon now form the inside of the output
.
When you pass mask
a Polygon with a hole (an exterior ring and an interior ring) like this:
https://gist.github.com/andrewharvey/971b9db1900a62efa7635f6a6d337ae7
It will simply add a new global exterior ring and make the input rings interior rings.
Although I’m not 100% sure if supported by the GeoJSON spec many applications which support GeoJSON allow for a GeoJSON Polygon
with an interior ring inside another interior ring to be interpreted as an island inside a hole inside a polygon.
I think the winding order of the interior rings should be used to spell out if the ring should be a hole or island, although this seems to make no difference in Leaflet.
So in Leaflet this works and visually creates the mask you expect.
https://gist.github.com/andrewharvey/c092a6c4932a4d94ecb6cd59dc935b90
However not all applications support this for example earcut does not: https://github.com/mapbox/earcut/issues/94.
I propose mask
should have an option for these islands within holes to be pulled out as separate exterior rings as part of a MultiPolygon
geometry type rather than inside the Polygon
type which is what earcut asks for.
I’m working on a PR at the moment to do this, appreciate any thoughts on the issue.
It should also fix the issue where you can’t round trip that second example back to the first by again applying the mask.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6
Top GitHub Comments
If that’s the case then the current output of turf.mask is wrong and it looks okay in Leaflet by luck, in which case what I propose shouldn’t be an option it should be the default behaviour.
This is a simple test case that fails to produce a valid MultiPolygon for both
difference
@ 6.0.1 andmask
@ 5.1.5, and instead produce an invalid Polygon.difference
@ 5.1.5 produces proper output.