Turfjs / Turfjs/turf

mask - option for islands in holes to be pulled out as separate MultiPolygon exterior rings

Open
#1,305 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

@turf/mask
Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

The 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:

polygon with a hole

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.

island in a hole in a polygon

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the mask function and its documentation, then compare the linked Polygon-with-hole and island-in-hole examples. Define the option's expected GeoJSON Polygon/MultiPolygon output and verify that the resulting geometry is accepted by applications such as earcut; done means the round-trip behavior described in the issue is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.