From 94a15c2c95f37119a2817dee22db2d845ec974be Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Sun, 9 Oct 2022 14:08:17 +1100 Subject: [PATCH 1/3] Add support for holes --- packages/turf-mask/README.md | 31 ++- packages/turf-mask/index.d.ts | 2 +- packages/turf-mask/index.js | 30 ++- packages/turf-mask/test.js | 52 +++- .../test/in/polygon-with-hole.geojson | 28 ++ .../turf-mask/test/out/multi-polygon.geojson | 242 +++++++++--------- .../turf-mask/test/out/overlapping.geojson | 34 +-- .../test/out/polygon-with-hole.geojson | 23 ++ 8 files changed, 286 insertions(+), 156 deletions(-) create mode 100644 packages/turf-mask/test/in/polygon-with-hole.geojson create mode 100644 packages/turf-mask/test/out/polygon-with-hole.geojson diff --git a/packages/turf-mask/README.md b/packages/turf-mask/README.md index 2c105ac48e..b7d0186cf4 100644 --- a/packages/turf-mask/README.md +++ b/packages/turf-mask/README.md @@ -8,31 +8,44 @@ Takes any type of [polygon][1] and an optional mask and returns a [polygon][1] e ### Parameters -* `polygon` **([FeatureCollection][2] | [Feature][3]<([Polygon][4] | [MultiPolygon][5])>)** GeoJSON Polygon used as interior rings or holes. -* `mask` **[Feature][3]<[Polygon][4]>?** GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used) +- `polygon` **([FeatureCollection][2] | [Feature][3]<([Polygon][4] | [MultiPolygon][5])>)** GeoJSON Polygon used as interior rings or holes. +- `mask` **[Feature][3]<[Polygon][4]>?** GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used) ### Examples ```javascript -var polygon = turf.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]); -var mask = turf.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]); +var polygon = turf.polygon([ + [ + [112, -21], + [116, -36], + [146, -39], + [153, -24], + [133, -10], + [112, -21], + ], +]); +var mask = turf.polygon([ + [ + [90, -55], + [170, -55], + [170, 10], + [90, 10], + [90, -55], + ], +]); var masked = turf.mask(polygon, mask); //addToMap -var addToMap = [masked] +var addToMap = [masked]; ``` Returns **[Feature][3]<[Polygon][4]>** Masked Polygon (exterior ring with holes). [1]: https://tools.ietf.org/html/rfc7946#section-3.1.6 - [2]: https://tools.ietf.org/html/rfc7946#section-3.3 - [3]: https://tools.ietf.org/html/rfc7946#section-3.2 - [4]: https://tools.ietf.org/html/rfc7946#section-3.1.6 - [5]: https://tools.ietf.org/html/rfc7946#section-3.1.7