63 lines
2.3 KiB
Markdown
63 lines
2.3 KiB
Markdown
# @turf/mask
|
|
|
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
|
|
## mask
|
|
|
|
Takes polygons or multipolygons and an optional mask, and returns an exterior
|
|
ring polygon with holes.
|
|
|
|
### Parameters
|
|
|
|
* `polygon` **([Polygon][1] | [MultiPolygon][2] | [Feature][3]<([Polygon][1] | [MultiPolygon][2])> | [FeatureCollection][4]<([Polygon][1] | [MultiPolygon][2])>)** GeoJSON polygon used as interior rings or holes
|
|
* `mask` **([Polygon][1] | [Feature][3]<[Polygon][1]>)?** GeoJSON polygon used as the exterior ring (if undefined, the world extent is used)
|
|
* `options` **[Object][5]** Optional parameters (optional, default `{}`)
|
|
|
|
* `options.mutate` **[boolean][6]** allows the `mask` GeoJSON input to be mutated (performance improvement if true) (optional, default `false`)
|
|
|
|
### Examples
|
|
|
|
```javascript
|
|
const polygon = turf.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]);
|
|
const mask = turf.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]);
|
|
|
|
const masked = turf.mask(polygon, mask);
|
|
|
|
//addToMap
|
|
const addToMap = [masked]
|
|
```
|
|
|
|
Returns **[Feature][3]<[Polygon][1]>** 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.1.7
|
|
|
|
[3]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
|
|
[4]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
|
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
|
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
|
|
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
|
|
---
|
|
|
|
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
|
|
### Installation
|
|
|
|
Install this single module individually:
|
|
|
|
```sh
|
|
$ npm install @turf/mask
|
|
```
|
|
|
|
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
|
|
```sh
|
|
$ npm install @turf/turf
|
|
```
|