@turf/mask 7.0.0-alpha.0 → 7.0.0-alpha.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -9
- package/dist/cjs/index.cjs +58 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/esm/index.d.mts +11 -0
- package/dist/esm/index.mjs +58 -0
- package/dist/esm/index.mjs.map +1 -0
- package/index.d.ts +4 -1
- package/package.json +28 -20
- package/dist/es/index.js +0 -79
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -86
package/README.md
CHANGED
|
@@ -35,26 +35,21 @@ Returns **[Feature][3]<[Polygon][4]>** Masked Polygon (exterior ring with holes)
|
|
|
35
35
|
|
|
36
36
|
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.7
|
|
37
37
|
|
|
38
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
39
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
40
|
-
./scripts/generate-readmes in the turf project. -->
|
|
38
|
+
<!-- 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. -->
|
|
41
39
|
|
|
42
40
|
---
|
|
43
41
|
|
|
44
|
-
This module is part of the [Turfjs project](
|
|
45
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
46
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
47
|
-
PRs and issues.
|
|
42
|
+
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.
|
|
48
43
|
|
|
49
44
|
### Installation
|
|
50
45
|
|
|
51
|
-
Install this module individually:
|
|
46
|
+
Install this single module individually:
|
|
52
47
|
|
|
53
48
|
```sh
|
|
54
49
|
$ npm install @turf/mask
|
|
55
50
|
```
|
|
56
51
|
|
|
57
|
-
Or install the
|
|
52
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
58
53
|
|
|
59
54
|
```sh
|
|
60
55
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
var _helpers = require('@turf/helpers');
|
|
6
|
+
var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
|
|
7
|
+
function mask(polygon, mask2) {
|
|
8
|
+
var maskPolygon = createMask(mask2);
|
|
9
|
+
var polygonOuters = null;
|
|
10
|
+
if (polygon.type === "FeatureCollection")
|
|
11
|
+
polygonOuters = unionFc(polygon);
|
|
12
|
+
else
|
|
13
|
+
polygonOuters = createGeomFromPolygonClippingOutput(
|
|
14
|
+
_polygonclipping2.default.union(polygon.geometry.coordinates)
|
|
15
|
+
);
|
|
16
|
+
polygonOuters.geometry.coordinates.forEach(function(contour) {
|
|
17
|
+
maskPolygon.geometry.coordinates.push(contour[0]);
|
|
18
|
+
});
|
|
19
|
+
return maskPolygon;
|
|
20
|
+
}
|
|
21
|
+
__name(mask, "mask");
|
|
22
|
+
function unionFc(fc) {
|
|
23
|
+
var unioned = fc.features.length === 2 ? _polygonclipping2.default.union(
|
|
24
|
+
fc.features[0].geometry.coordinates,
|
|
25
|
+
fc.features[1].geometry.coordinates
|
|
26
|
+
) : _polygonclipping2.default.union.apply(
|
|
27
|
+
_polygonclipping2.default,
|
|
28
|
+
fc.features.map(function(f) {
|
|
29
|
+
return f.geometry.coordinates;
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
return createGeomFromPolygonClippingOutput(unioned);
|
|
33
|
+
}
|
|
34
|
+
__name(unionFc, "unionFc");
|
|
35
|
+
function createGeomFromPolygonClippingOutput(unioned) {
|
|
36
|
+
return _helpers.multiPolygon.call(void 0, unioned);
|
|
37
|
+
}
|
|
38
|
+
__name(createGeomFromPolygonClippingOutput, "createGeomFromPolygonClippingOutput");
|
|
39
|
+
function createMask(mask2) {
|
|
40
|
+
var world = [
|
|
41
|
+
[
|
|
42
|
+
[180, 90],
|
|
43
|
+
[-180, 90],
|
|
44
|
+
[-180, -90],
|
|
45
|
+
[180, -90],
|
|
46
|
+
[180, 90]
|
|
47
|
+
]
|
|
48
|
+
];
|
|
49
|
+
var coordinates = mask2 && mask2.geometry.coordinates || world;
|
|
50
|
+
return _helpers.polygon.call(void 0, coordinates);
|
|
51
|
+
}
|
|
52
|
+
__name(createMask, "createMask");
|
|
53
|
+
var turf_mask_default = mask;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
exports.default = turf_mask_default; exports.mask = mask;
|
|
58
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"names":["mask"],"mappings":";;;;AAAA,SAAS,WAAW,eAAe,oBAAoB;AACvD,OAAO,qBAAqB;AAkB5B,SAAS,KAAK,SAASA,OAAM;AAE3B,MAAI,cAAc,WAAWA,KAAI;AAEjC,MAAI,gBAAgB;AACpB,MAAI,QAAQ,SAAS;AAAqB,oBAAgB,QAAQ,OAAO;AAAA;AAEvE,oBAAgB;AAAA,MACd,gBAAgB,MAAM,QAAQ,SAAS,WAAW;AAAA,IACpD;AAEF,gBAAc,SAAS,YAAY,QAAQ,SAAU,SAAS;AAC5D,gBAAY,SAAS,YAAY,KAAK,QAAQ,CAAC,CAAC;AAAA,EAClD,CAAC;AAED,SAAO;AACT;AAhBS;AAkBT,SAAS,QAAQ,IAAI;AACnB,MAAI,UACF,GAAG,SAAS,WAAW,IACnB,gBAAgB;AAAA,IACd,GAAG,SAAS,CAAC,EAAE,SAAS;AAAA,IACxB,GAAG,SAAS,CAAC,EAAE,SAAS;AAAA,EAC1B,IACA,gBAAgB,MAAM;AAAA,IACpB;AAAA,IACA,GAAG,SAAS,IAAI,SAAU,GAAG;AAC3B,aAAO,EAAE,SAAS;AAAA,IACpB,CAAC;AAAA,EACH;AACN,SAAO,oCAAoC,OAAO;AACpD;AAdS;AAgBT,SAAS,oCAAoC,SAAS;AACpD,SAAO,aAAa,OAAO;AAC7B;AAFS;AAWT,SAAS,WAAWA,OAAM;AACxB,MAAI,QAAQ;AAAA,IACV;AAAA,MACE,CAAC,KAAK,EAAE;AAAA,MACR,CAAC,MAAM,EAAE;AAAA,MACT,CAAC,MAAM,GAAG;AAAA,MACV,CAAC,KAAK,GAAG;AAAA,MACT,CAAC,KAAK,EAAE;AAAA,IACV;AAAA,EACF;AACA,MAAI,cAAeA,SAAQA,MAAK,SAAS,eAAgB;AACzD,SAAO,cAAc,WAAW;AAClC;AAZS;AAeT,IAAO,oBAAQ","sourcesContent":["import { polygon as createPolygon, multiPolygon } from \"@turf/helpers\";\nimport polygonClipping from \"polygon-clipping\";\n\n/**\n * Takes any type of {@link Polygon|polygon} and an optional mask and returns a {@link Polygon|polygon} exterior ring with holes.\n *\n * @name mask\n * @param {FeatureCollection|Feature<Polygon|MultiPolygon>} polygon GeoJSON Polygon used as interior rings or holes.\n * @param {Feature<Polygon>} [mask] GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used)\n * @returns {Feature<Polygon>} Masked Polygon (exterior ring with holes).\n * @example\n * var polygon = turf.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]);\n * var mask = turf.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]);\n *\n * var masked = turf.mask(polygon, mask);\n *\n * //addToMap\n * var addToMap = [masked]\n */\nfunction mask(polygon, mask) {\n // Define mask\n var maskPolygon = createMask(mask);\n\n var polygonOuters = null;\n if (polygon.type === \"FeatureCollection\") polygonOuters = unionFc(polygon);\n else\n polygonOuters = createGeomFromPolygonClippingOutput(\n polygonClipping.union(polygon.geometry.coordinates)\n );\n\n polygonOuters.geometry.coordinates.forEach(function (contour) {\n maskPolygon.geometry.coordinates.push(contour[0]);\n });\n\n return maskPolygon;\n}\n\nfunction unionFc(fc) {\n var unioned =\n fc.features.length === 2\n ? polygonClipping.union(\n fc.features[0].geometry.coordinates,\n fc.features[1].geometry.coordinates\n )\n : polygonClipping.union.apply(\n polygonClipping,\n fc.features.map(function (f) {\n return f.geometry.coordinates;\n })\n );\n return createGeomFromPolygonClippingOutput(unioned);\n}\n\nfunction createGeomFromPolygonClippingOutput(unioned) {\n return multiPolygon(unioned);\n}\n\n/**\n * Create Mask Coordinates\n *\n * @private\n * @param {Feature<Polygon>} [mask] default to world if undefined\n * @returns {Feature<Polygon>} mask coordinate\n */\nfunction createMask(mask) {\n var world = [\n [\n [180, 90],\n [-180, 90],\n [-180, -90],\n [180, -90],\n [180, 90],\n ],\n ];\n var coordinates = (mask && mask.geometry.coordinates) || world;\n return createPolygon(coordinates);\n}\n\nexport { mask };\nexport default mask;\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Polygon, MultiPolygon, Feature, FeatureCollection } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#mask
|
|
5
|
+
*/
|
|
6
|
+
declare function mask<T extends Polygon | MultiPolygon>(
|
|
7
|
+
poly: Feature<T> | FeatureCollection<T> | T,
|
|
8
|
+
mask?: Feature<Polygon> | Polygon
|
|
9
|
+
): Feature<Polygon>;
|
|
10
|
+
|
|
11
|
+
export { mask as default, mask };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Polygon, MultiPolygon, Feature, FeatureCollection } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#mask
|
|
5
|
+
*/
|
|
6
|
+
declare function mask<T extends Polygon | MultiPolygon>(
|
|
7
|
+
poly: Feature<T> | FeatureCollection<T> | T,
|
|
8
|
+
mask?: Feature<Polygon> | Polygon
|
|
9
|
+
): Feature<Polygon>;
|
|
10
|
+
|
|
11
|
+
export { mask as default, mask };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
import { polygon as createPolygon, multiPolygon } from "@turf/helpers";
|
|
6
|
+
import polygonClipping from "polygon-clipping";
|
|
7
|
+
function mask(polygon, mask2) {
|
|
8
|
+
var maskPolygon = createMask(mask2);
|
|
9
|
+
var polygonOuters = null;
|
|
10
|
+
if (polygon.type === "FeatureCollection")
|
|
11
|
+
polygonOuters = unionFc(polygon);
|
|
12
|
+
else
|
|
13
|
+
polygonOuters = createGeomFromPolygonClippingOutput(
|
|
14
|
+
polygonClipping.union(polygon.geometry.coordinates)
|
|
15
|
+
);
|
|
16
|
+
polygonOuters.geometry.coordinates.forEach(function(contour) {
|
|
17
|
+
maskPolygon.geometry.coordinates.push(contour[0]);
|
|
18
|
+
});
|
|
19
|
+
return maskPolygon;
|
|
20
|
+
}
|
|
21
|
+
__name(mask, "mask");
|
|
22
|
+
function unionFc(fc) {
|
|
23
|
+
var unioned = fc.features.length === 2 ? polygonClipping.union(
|
|
24
|
+
fc.features[0].geometry.coordinates,
|
|
25
|
+
fc.features[1].geometry.coordinates
|
|
26
|
+
) : polygonClipping.union.apply(
|
|
27
|
+
polygonClipping,
|
|
28
|
+
fc.features.map(function(f) {
|
|
29
|
+
return f.geometry.coordinates;
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
return createGeomFromPolygonClippingOutput(unioned);
|
|
33
|
+
}
|
|
34
|
+
__name(unionFc, "unionFc");
|
|
35
|
+
function createGeomFromPolygonClippingOutput(unioned) {
|
|
36
|
+
return multiPolygon(unioned);
|
|
37
|
+
}
|
|
38
|
+
__name(createGeomFromPolygonClippingOutput, "createGeomFromPolygonClippingOutput");
|
|
39
|
+
function createMask(mask2) {
|
|
40
|
+
var world = [
|
|
41
|
+
[
|
|
42
|
+
[180, 90],
|
|
43
|
+
[-180, 90],
|
|
44
|
+
[-180, -90],
|
|
45
|
+
[180, -90],
|
|
46
|
+
[180, 90]
|
|
47
|
+
]
|
|
48
|
+
];
|
|
49
|
+
var coordinates = mask2 && mask2.geometry.coordinates || world;
|
|
50
|
+
return createPolygon(coordinates);
|
|
51
|
+
}
|
|
52
|
+
__name(createMask, "createMask");
|
|
53
|
+
var turf_mask_default = mask;
|
|
54
|
+
export {
|
|
55
|
+
turf_mask_default as default,
|
|
56
|
+
mask
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { polygon as createPolygon, multiPolygon } from \"@turf/helpers\";\nimport polygonClipping from \"polygon-clipping\";\n\n/**\n * Takes any type of {@link Polygon|polygon} and an optional mask and returns a {@link Polygon|polygon} exterior ring with holes.\n *\n * @name mask\n * @param {FeatureCollection|Feature<Polygon|MultiPolygon>} polygon GeoJSON Polygon used as interior rings or holes.\n * @param {Feature<Polygon>} [mask] GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used)\n * @returns {Feature<Polygon>} Masked Polygon (exterior ring with holes).\n * @example\n * var polygon = turf.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]);\n * var mask = turf.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]);\n *\n * var masked = turf.mask(polygon, mask);\n *\n * //addToMap\n * var addToMap = [masked]\n */\nfunction mask(polygon, mask) {\n // Define mask\n var maskPolygon = createMask(mask);\n\n var polygonOuters = null;\n if (polygon.type === \"FeatureCollection\") polygonOuters = unionFc(polygon);\n else\n polygonOuters = createGeomFromPolygonClippingOutput(\n polygonClipping.union(polygon.geometry.coordinates)\n );\n\n polygonOuters.geometry.coordinates.forEach(function (contour) {\n maskPolygon.geometry.coordinates.push(contour[0]);\n });\n\n return maskPolygon;\n}\n\nfunction unionFc(fc) {\n var unioned =\n fc.features.length === 2\n ? polygonClipping.union(\n fc.features[0].geometry.coordinates,\n fc.features[1].geometry.coordinates\n )\n : polygonClipping.union.apply(\n polygonClipping,\n fc.features.map(function (f) {\n return f.geometry.coordinates;\n })\n );\n return createGeomFromPolygonClippingOutput(unioned);\n}\n\nfunction createGeomFromPolygonClippingOutput(unioned) {\n return multiPolygon(unioned);\n}\n\n/**\n * Create Mask Coordinates\n *\n * @private\n * @param {Feature<Polygon>} [mask] default to world if undefined\n * @returns {Feature<Polygon>} mask coordinate\n */\nfunction createMask(mask) {\n var world = [\n [\n [180, 90],\n [-180, 90],\n [-180, -90],\n [180, -90],\n [180, 90],\n ],\n ];\n var coordinates = (mask && mask.geometry.coordinates) || world;\n return createPolygon(coordinates);\n}\n\nexport { mask };\nexport default mask;\n"],"mappings":";;;;AAAA,SAAS,WAAW,eAAe,oBAAoB;AACvD,OAAO,qBAAqB;AAkB5B,SAAS,KAAK,SAASA,OAAM;AAE3B,MAAI,cAAc,WAAWA,KAAI;AAEjC,MAAI,gBAAgB;AACpB,MAAI,QAAQ,SAAS;AAAqB,oBAAgB,QAAQ,OAAO;AAAA;AAEvE,oBAAgB;AAAA,MACd,gBAAgB,MAAM,QAAQ,SAAS,WAAW;AAAA,IACpD;AAEF,gBAAc,SAAS,YAAY,QAAQ,SAAU,SAAS;AAC5D,gBAAY,SAAS,YAAY,KAAK,QAAQ,CAAC,CAAC;AAAA,EAClD,CAAC;AAED,SAAO;AACT;AAhBS;AAkBT,SAAS,QAAQ,IAAI;AACnB,MAAI,UACF,GAAG,SAAS,WAAW,IACnB,gBAAgB;AAAA,IACd,GAAG,SAAS,CAAC,EAAE,SAAS;AAAA,IACxB,GAAG,SAAS,CAAC,EAAE,SAAS;AAAA,EAC1B,IACA,gBAAgB,MAAM;AAAA,IACpB;AAAA,IACA,GAAG,SAAS,IAAI,SAAU,GAAG;AAC3B,aAAO,EAAE,SAAS;AAAA,IACpB,CAAC;AAAA,EACH;AACN,SAAO,oCAAoC,OAAO;AACpD;AAdS;AAgBT,SAAS,oCAAoC,SAAS;AACpD,SAAO,aAAa,OAAO;AAC7B;AAFS;AAWT,SAAS,WAAWA,OAAM;AACxB,MAAI,QAAQ;AAAA,IACV;AAAA,MACE,CAAC,KAAK,EAAE;AAAA,MACR,CAAC,MAAM,EAAE;AAAA,MACT,CAAC,MAAM,GAAG;AAAA,MACV,CAAC,KAAK,GAAG;AAAA,MACT,CAAC,KAAK,EAAE;AAAA,IACV;AAAA,EACF;AACA,MAAI,cAAeA,SAAQA,MAAK,SAAS,eAAgB;AACzD,SAAO,cAAc,WAAW;AAClC;AAZS;AAeT,IAAO,oBAAQ;","names":["mask"]}
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { Feature, Polygon, MultiPolygon, FeatureCollection } from "geojson";
|
|
|
3
3
|
/**
|
|
4
4
|
* http://turfjs.org/docs/#mask
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
declare function mask<T extends Polygon | MultiPolygon>(
|
|
7
7
|
poly: Feature<T> | FeatureCollection<T> | T,
|
|
8
8
|
mask?: Feature<Polygon> | Polygon
|
|
9
9
|
): Feature<Polygon>;
|
|
10
|
+
|
|
11
|
+
export { mask };
|
|
12
|
+
export default mask;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/mask",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf mask module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,41 +21,49 @@
|
|
|
21
21
|
"mask",
|
|
22
22
|
"polygon"
|
|
23
23
|
],
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"main": "dist/cjs/index.cjs",
|
|
26
|
+
"module": "dist/esm/index.mjs",
|
|
27
|
+
"types": "dist/cjs/index.d.ts",
|
|
26
28
|
"exports": {
|
|
27
29
|
"./package.json": "./package.json",
|
|
28
30
|
".": {
|
|
29
|
-
"import":
|
|
30
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/index.d.mts",
|
|
33
|
+
"default": "./dist/esm/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/index.d.ts",
|
|
37
|
+
"default": "./dist/cjs/index.cjs"
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
},
|
|
33
|
-
"types": "index.d.ts",
|
|
34
41
|
"sideEffects": false,
|
|
35
42
|
"files": [
|
|
36
43
|
"dist",
|
|
37
44
|
"index.d.ts"
|
|
38
45
|
],
|
|
39
46
|
"scripts": {
|
|
40
|
-
"bench": "
|
|
41
|
-
"build": "
|
|
42
|
-
"docs": "
|
|
43
|
-
"test": "npm-run-all test:*",
|
|
44
|
-
"test:tape": "
|
|
47
|
+
"bench": "tsx bench.ts",
|
|
48
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
49
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
50
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
51
|
+
"test:tape": "tsx test.ts",
|
|
45
52
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
46
53
|
},
|
|
47
54
|
"devDependencies": {
|
|
48
|
-
"benchmark": "
|
|
49
|
-
"load-json-file": "
|
|
50
|
-
"mkdirp": "
|
|
51
|
-
"npm-run-all": "
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
+
"benchmark": "^2.1.4",
|
|
56
|
+
"load-json-file": "^7.0.1",
|
|
57
|
+
"mkdirp": "^3.0.1",
|
|
58
|
+
"npm-run-all": "^4.1.5",
|
|
59
|
+
"tape": "^5.7.2",
|
|
60
|
+
"tsup": "^8.0.1",
|
|
61
|
+
"tsx": "^4.6.2",
|
|
62
|
+
"write-json-file": "^5.0.0"
|
|
55
63
|
},
|
|
56
64
|
"dependencies": {
|
|
57
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
65
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
58
66
|
"polygon-clipping": "^0.15.3"
|
|
59
67
|
},
|
|
60
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
61
69
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { polygon, multiPolygon } from '@turf/helpers';
|
|
2
|
-
import polygonClipping from 'polygon-clipping';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Takes any type of {@link Polygon|polygon} and an optional mask and returns a {@link Polygon|polygon} exterior ring with holes.
|
|
6
|
-
*
|
|
7
|
-
* @name mask
|
|
8
|
-
* @param {FeatureCollection|Feature<Polygon|MultiPolygon>} polygon GeoJSON Polygon used as interior rings or holes.
|
|
9
|
-
* @param {Feature<Polygon>} [mask] GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used)
|
|
10
|
-
* @returns {Feature<Polygon>} Masked Polygon (exterior ring with holes).
|
|
11
|
-
* @example
|
|
12
|
-
* var polygon = turf.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]);
|
|
13
|
-
* var mask = turf.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]);
|
|
14
|
-
*
|
|
15
|
-
* var masked = turf.mask(polygon, mask);
|
|
16
|
-
*
|
|
17
|
-
* //addToMap
|
|
18
|
-
* var addToMap = [masked]
|
|
19
|
-
*/
|
|
20
|
-
function mask(polygon, mask) {
|
|
21
|
-
// Define mask
|
|
22
|
-
var maskPolygon = createMask(mask);
|
|
23
|
-
|
|
24
|
-
var polygonOuters = null;
|
|
25
|
-
if (polygon.type === "FeatureCollection") polygonOuters = unionFc(polygon);
|
|
26
|
-
else
|
|
27
|
-
polygonOuters = createGeomFromPolygonClippingOutput(
|
|
28
|
-
polygonClipping.union(polygon.geometry.coordinates)
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
polygonOuters.geometry.coordinates.forEach(function (contour) {
|
|
32
|
-
maskPolygon.geometry.coordinates.push(contour[0]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return maskPolygon;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function unionFc(fc) {
|
|
39
|
-
var unioned =
|
|
40
|
-
fc.features.length === 2
|
|
41
|
-
? polygonClipping.union(
|
|
42
|
-
fc.features[0].geometry.coordinates,
|
|
43
|
-
fc.features[1].geometry.coordinates
|
|
44
|
-
)
|
|
45
|
-
: polygonClipping.union.apply(
|
|
46
|
-
polygonClipping,
|
|
47
|
-
fc.features.map(function (f) {
|
|
48
|
-
return f.geometry.coordinates;
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
return createGeomFromPolygonClippingOutput(unioned);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function createGeomFromPolygonClippingOutput(unioned) {
|
|
55
|
-
return multiPolygon(unioned);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Create Mask Coordinates
|
|
60
|
-
*
|
|
61
|
-
* @private
|
|
62
|
-
* @param {Feature<Polygon>} [mask] default to world if undefined
|
|
63
|
-
* @returns {Feature<Polygon>} mask coordinate
|
|
64
|
-
*/
|
|
65
|
-
function createMask(mask) {
|
|
66
|
-
var world = [
|
|
67
|
-
[
|
|
68
|
-
[180, 90],
|
|
69
|
-
[-180, 90],
|
|
70
|
-
[-180, -90],
|
|
71
|
-
[180, -90],
|
|
72
|
-
[180, 90],
|
|
73
|
-
],
|
|
74
|
-
];
|
|
75
|
-
var coordinates = (mask && mask.geometry.coordinates) || world;
|
|
76
|
-
return polygon(coordinates);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default mask;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var helpers = require('@turf/helpers');
|
|
4
|
-
var polygonClipping = require('polygon-clipping');
|
|
5
|
-
|
|
6
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
7
|
-
|
|
8
|
-
var polygonClipping__default = /*#__PURE__*/_interopDefaultLegacy(polygonClipping);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Takes any type of {@link Polygon|polygon} and an optional mask and returns a {@link Polygon|polygon} exterior ring with holes.
|
|
12
|
-
*
|
|
13
|
-
* @name mask
|
|
14
|
-
* @param {FeatureCollection|Feature<Polygon|MultiPolygon>} polygon GeoJSON Polygon used as interior rings or holes.
|
|
15
|
-
* @param {Feature<Polygon>} [mask] GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used)
|
|
16
|
-
* @returns {Feature<Polygon>} Masked Polygon (exterior ring with holes).
|
|
17
|
-
* @example
|
|
18
|
-
* var polygon = turf.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]);
|
|
19
|
-
* var mask = turf.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]);
|
|
20
|
-
*
|
|
21
|
-
* var masked = turf.mask(polygon, mask);
|
|
22
|
-
*
|
|
23
|
-
* //addToMap
|
|
24
|
-
* var addToMap = [masked]
|
|
25
|
-
*/
|
|
26
|
-
function mask(polygon, mask) {
|
|
27
|
-
// Define mask
|
|
28
|
-
var maskPolygon = createMask(mask);
|
|
29
|
-
|
|
30
|
-
var polygonOuters = null;
|
|
31
|
-
if (polygon.type === "FeatureCollection") polygonOuters = unionFc(polygon);
|
|
32
|
-
else
|
|
33
|
-
polygonOuters = createGeomFromPolygonClippingOutput(
|
|
34
|
-
polygonClipping__default['default'].union(polygon.geometry.coordinates)
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
polygonOuters.geometry.coordinates.forEach(function (contour) {
|
|
38
|
-
maskPolygon.geometry.coordinates.push(contour[0]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return maskPolygon;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function unionFc(fc) {
|
|
45
|
-
var unioned =
|
|
46
|
-
fc.features.length === 2
|
|
47
|
-
? polygonClipping__default['default'].union(
|
|
48
|
-
fc.features[0].geometry.coordinates,
|
|
49
|
-
fc.features[1].geometry.coordinates
|
|
50
|
-
)
|
|
51
|
-
: polygonClipping__default['default'].union.apply(
|
|
52
|
-
polygonClipping__default['default'],
|
|
53
|
-
fc.features.map(function (f) {
|
|
54
|
-
return f.geometry.coordinates;
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
return createGeomFromPolygonClippingOutput(unioned);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function createGeomFromPolygonClippingOutput(unioned) {
|
|
61
|
-
return helpers.multiPolygon(unioned);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Create Mask Coordinates
|
|
66
|
-
*
|
|
67
|
-
* @private
|
|
68
|
-
* @param {Feature<Polygon>} [mask] default to world if undefined
|
|
69
|
-
* @returns {Feature<Polygon>} mask coordinate
|
|
70
|
-
*/
|
|
71
|
-
function createMask(mask) {
|
|
72
|
-
var world = [
|
|
73
|
-
[
|
|
74
|
-
[180, 90],
|
|
75
|
-
[-180, 90],
|
|
76
|
-
[-180, -90],
|
|
77
|
-
[180, -90],
|
|
78
|
-
[180, 90],
|
|
79
|
-
],
|
|
80
|
-
];
|
|
81
|
-
var coordinates = (mask && mask.geometry.coordinates) || world;
|
|
82
|
-
return helpers.polygon(coordinates);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
module.exports = mask;
|
|
86
|
-
module.exports.default = mask;
|