@turf/union 7.1.0 → 7.3.0
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 +44 -24
- package/dist/cjs/index.cjs +9 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +40 -21
- package/dist/esm/index.d.ts +40 -21
- package/dist/esm/index.js +9 -12
- package/dist/esm/index.js.map +1 -1
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -4,49 +4,69 @@
|
|
|
4
4
|
|
|
5
5
|
## union
|
|
6
6
|
|
|
7
|
-
Takes input
|
|
7
|
+
Takes a collection of input polygons and returns a combined polygon. If the
|
|
8
|
+
input polygons are not contiguous, this function returns a multi-polygon
|
|
9
|
+
feature.
|
|
8
10
|
|
|
9
11
|
### Parameters
|
|
10
12
|
|
|
11
|
-
* `
|
|
13
|
+
* `features` **[FeatureCollection][1]<([Polygon][2] | [MultiPolygon][3])>** input polygon features
|
|
12
14
|
* `options` **[Object][4]** Optional Parameters (optional, default `{}`)
|
|
13
15
|
|
|
14
|
-
* `options.properties` **[
|
|
16
|
+
* `options.properties` **[GeoJsonProperties][5]** properties to assign to output feature (optional, default `{}`)
|
|
15
17
|
|
|
16
18
|
### Examples
|
|
17
19
|
|
|
18
20
|
```javascript
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
const poly1 = turf.polygon(
|
|
22
|
+
[
|
|
23
|
+
[
|
|
24
|
+
[-82.574787, 35.594087],
|
|
25
|
+
[-82.574787, 35.615581],
|
|
26
|
+
[-82.545261, 35.615581],
|
|
27
|
+
[-82.545261, 35.594087],
|
|
28
|
+
[-82.574787, 35.594087],
|
|
29
|
+
],
|
|
30
|
+
],
|
|
31
|
+
{ fill: "#0f0" }
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const poly2 = turf.polygon(
|
|
35
|
+
[
|
|
36
|
+
[
|
|
37
|
+
[-82.560024, 35.585153],
|
|
38
|
+
[-82.560024, 35.602602],
|
|
39
|
+
[-82.52964, 35.602602],
|
|
40
|
+
[-82.52964, 35.585153],
|
|
41
|
+
[-82.560024, 35.585153],
|
|
42
|
+
],
|
|
43
|
+
],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const union = turf.union(turf.featureCollection([poly1, poly2]));
|
|
35
47
|
|
|
36
48
|
//addToMap
|
|
37
|
-
|
|
49
|
+
const addToMap = { poly1, poly2, union };
|
|
50
|
+
|
|
51
|
+
poly1.properties.fill = "#0f0";
|
|
52
|
+
poly2.properties.fill = "#00f";
|
|
53
|
+
union.properties.stroke = "red";
|
|
54
|
+
union.properties["stroke-width"] = 4;
|
|
55
|
+
union.properties.fill = "transparent";
|
|
38
56
|
```
|
|
39
57
|
|
|
40
|
-
Returns **[Feature][
|
|
58
|
+
Returns **([Feature][5]<([Polygon][2] | [MultiPolygon][3])> | null)** a combined polygon or multi-polygon feature, or null if there were no input polygons to combine
|
|
41
59
|
|
|
42
|
-
[1]: https://tools.ietf.org/html/rfc7946#section-3.
|
|
60
|
+
[1]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
43
61
|
|
|
44
|
-
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.
|
|
62
|
+
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
45
63
|
|
|
46
|
-
[3]: https://tools.ietf.org/html/rfc7946#section-3.
|
|
64
|
+
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.7
|
|
47
65
|
|
|
48
66
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
49
67
|
|
|
68
|
+
[5]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
69
|
+
|
|
50
70
|
<!-- 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. -->
|
|
51
71
|
|
|
52
72
|
---
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
2
|
-
var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// index.ts
|
|
2
|
+
var _polyclipts = require('polyclip-ts'); var polyclip = _interopRequireWildcard(_polyclipts);
|
|
3
3
|
var _helpers = require('@turf/helpers');
|
|
4
4
|
var _meta = require('@turf/meta');
|
|
5
|
-
function
|
|
5
|
+
function union2(features, options = {}) {
|
|
6
6
|
const geoms = [];
|
|
7
7
|
_meta.geomEach.call(void 0, features, (geom) => {
|
|
8
8
|
geoms.push(geom.coordinates);
|
|
@@ -10,17 +10,14 @@ function union(features, options = {}) {
|
|
|
10
10
|
if (geoms.length < 2) {
|
|
11
11
|
throw new Error("Must have at least 2 geometries");
|
|
12
12
|
}
|
|
13
|
-
const unioned =
|
|
14
|
-
if (unioned.length === 0)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return _helpers.polygon.call(void 0, unioned[0], options.properties);
|
|
18
|
-
else
|
|
19
|
-
return _helpers.multiPolygon.call(void 0, unioned, options.properties);
|
|
13
|
+
const unioned = polyclip.union(geoms[0], ...geoms.slice(1));
|
|
14
|
+
if (unioned.length === 0) return null;
|
|
15
|
+
if (unioned.length === 1) return _helpers.polygon.call(void 0, unioned[0], options.properties);
|
|
16
|
+
else return _helpers.multiPolygon.call(void 0, unioned, options.properties);
|
|
20
17
|
}
|
|
21
|
-
var
|
|
18
|
+
var index_default = union2;
|
|
22
19
|
|
|
23
20
|
|
|
24
21
|
|
|
25
|
-
exports.default =
|
|
22
|
+
exports.default = index_default; exports.union = union2;
|
|
26
23
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-union/dist/cjs/index.cjs","../../index.ts"],"names":["union"],"mappings":"AAAA;ACAA,8FAA0B;AAC1B,wCAAsC;AACtC,kCAAyB;AAyDzB,SAASA,MAAAA,CACP,QAAA,EACA,QAAA,EAA8B,CAAC,CAAA,EACY;AAC3C,EAAA,MAAM,MAAA,EAAyB,CAAC,CAAA;AAChC,EAAA,4BAAA,QAAS,EAAU,CAAC,IAAA,EAAA,GAAS;AAC3B,IAAA,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,WAA4B,CAAA;AAAA,EAC9C,CAAC,CAAA;AAED,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,EAAS,CAAA,EAAG;AACpB,IAAA,MAAM,IAAI,KAAA,CAAM,iCAAiC,CAAA;AAAA,EACnD;AAEA,EAAA,MAAM,QAAA,EAAmB,QAAA,CAAA,KAAA,CAAM,KAAA,CAAM,CAAC,CAAA,EAAG,GAAG,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA;AAC1D,EAAA,GAAA,CAAI,OAAA,CAAQ,OAAA,IAAW,CAAA,EAAG,OAAO,IAAA;AACjC,EAAA,GAAA,CAAI,OAAA,CAAQ,OAAA,IAAW,CAAA,EAAG,OAAO,8BAAA,OAAQ,CAAQ,CAAC,CAAA,EAAG,OAAA,CAAQ,UAAU,CAAA;AAAA,EAAA,KAClE,OAAO,mCAAA,OAAa,EAAS,OAAA,CAAQ,UAAU,CAAA;AACtD;AAGA,IAAO,cAAA,EAAQA,MAAAA;AD7Df;AACE;AACA;AACF,wDAAC","file":"/home/runner/work/turf/turf/packages/turf-union/dist/cjs/index.cjs","sourcesContent":[null,"import * as polyclip from \"polyclip-ts\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport {\n FeatureCollection,\n Feature,\n Polygon,\n MultiPolygon,\n GeoJsonProperties,\n} from \"geojson\";\n\n/**\n * Takes a collection of input polygons and returns a combined polygon. If the\n * input polygons are not contiguous, this function returns a multi-polygon\n * feature.\n *\n * @function\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features\n * @param {Object} [options={}] Optional Parameters\n * @param {GeoJsonProperties} [options.properties={}] properties to assign to output feature\n * @returns {Feature<(Polygon|MultiPolygon)>|null} a combined polygon or multi-polygon feature, or null if there were no input polygons to combine\n * @example\n *\n * const poly1 = turf.polygon(\n * [\n * [\n * [-82.574787, 35.594087],\n * [-82.574787, 35.615581],\n * [-82.545261, 35.615581],\n * [-82.545261, 35.594087],\n * [-82.574787, 35.594087],\n * ],\n * ],\n * { fill: \"#0f0\" }\n * );\n *\n * const poly2 = turf.polygon(\n * [\n * [\n * [-82.560024, 35.585153],\n * [-82.560024, 35.602602],\n * [-82.52964, 35.602602],\n * [-82.52964, 35.585153],\n * [-82.560024, 35.585153],\n * ],\n * ],\n * );\n *\n * const union = turf.union(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * const addToMap = { poly1, poly2, union };\n *\n * poly1.properties.fill = \"#0f0\";\n * poly2.properties.fill = \"#00f\";\n * union.properties.stroke = \"red\";\n * union.properties[\"stroke-width\"] = 4;\n * union.properties.fill = \"transparent\";\n */\nfunction union<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: { properties?: P } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polyclip.Geom[] = [];\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polyclip.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least 2 geometries\");\n }\n\n const unioned = polyclip.union(geoms[0], ...geoms.slice(1));\n if (unioned.length === 0) return null;\n if (unioned.length === 1) return polygon(unioned[0], options.properties);\n else return multiPolygon(unioned, options.properties);\n}\n\nexport { union };\nexport default union;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,33 +1,52 @@
|
|
|
1
1
|
import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Takes input
|
|
4
|
+
* Takes a collection of input polygons and returns a combined polygon. If the
|
|
5
|
+
* input polygons are not contiguous, this function returns a multi-polygon
|
|
6
|
+
* feature.
|
|
5
7
|
*
|
|
6
|
-
* @
|
|
7
|
-
* @param {
|
|
8
|
+
* @function
|
|
9
|
+
* @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features
|
|
8
10
|
* @param {Object} [options={}] Optional Parameters
|
|
9
|
-
* @param {
|
|
10
|
-
* @returns {Feature<(Polygon|MultiPolygon)
|
|
11
|
+
* @param {GeoJsonProperties} [options.properties={}] properties to assign to output feature
|
|
12
|
+
* @returns {Feature<(Polygon|MultiPolygon)>|null} a combined polygon or multi-polygon feature, or null if there were no input polygons to combine
|
|
11
13
|
* @example
|
|
12
|
-
* var poly1 = turf.polygon([[
|
|
13
|
-
* [-82.574787, 35.594087],
|
|
14
|
-
* [-82.574787, 35.615581],
|
|
15
|
-
* [-82.545261, 35.615581],
|
|
16
|
-
* [-82.545261, 35.594087],
|
|
17
|
-
* [-82.574787, 35.594087]
|
|
18
|
-
* ]], {"fill": "#0f0"});
|
|
19
|
-
* var poly2 = turf.polygon([[
|
|
20
|
-
* [-82.560024, 35.585153],
|
|
21
|
-
* [-82.560024, 35.602602],
|
|
22
|
-
* [-82.52964, 35.602602],
|
|
23
|
-
* [-82.52964, 35.585153],
|
|
24
|
-
* [-82.560024, 35.585153]
|
|
25
|
-
* ]], {"fill": "#00f"});
|
|
26
14
|
*
|
|
27
|
-
*
|
|
15
|
+
* const poly1 = turf.polygon(
|
|
16
|
+
* [
|
|
17
|
+
* [
|
|
18
|
+
* [-82.574787, 35.594087],
|
|
19
|
+
* [-82.574787, 35.615581],
|
|
20
|
+
* [-82.545261, 35.615581],
|
|
21
|
+
* [-82.545261, 35.594087],
|
|
22
|
+
* [-82.574787, 35.594087],
|
|
23
|
+
* ],
|
|
24
|
+
* ],
|
|
25
|
+
* { fill: "#0f0" }
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* const poly2 = turf.polygon(
|
|
29
|
+
* [
|
|
30
|
+
* [
|
|
31
|
+
* [-82.560024, 35.585153],
|
|
32
|
+
* [-82.560024, 35.602602],
|
|
33
|
+
* [-82.52964, 35.602602],
|
|
34
|
+
* [-82.52964, 35.585153],
|
|
35
|
+
* [-82.560024, 35.585153],
|
|
36
|
+
* ],
|
|
37
|
+
* ],
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* const union = turf.union(turf.featureCollection([poly1, poly2]));
|
|
28
41
|
*
|
|
29
42
|
* //addToMap
|
|
30
|
-
*
|
|
43
|
+
* const addToMap = { poly1, poly2, union };
|
|
44
|
+
*
|
|
45
|
+
* poly1.properties.fill = "#0f0";
|
|
46
|
+
* poly2.properties.fill = "#00f";
|
|
47
|
+
* union.properties.stroke = "red";
|
|
48
|
+
* union.properties["stroke-width"] = 4;
|
|
49
|
+
* union.properties.fill = "transparent";
|
|
31
50
|
*/
|
|
32
51
|
declare function union<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
|
|
33
52
|
properties?: P;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,33 +1,52 @@
|
|
|
1
1
|
import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Takes input
|
|
4
|
+
* Takes a collection of input polygons and returns a combined polygon. If the
|
|
5
|
+
* input polygons are not contiguous, this function returns a multi-polygon
|
|
6
|
+
* feature.
|
|
5
7
|
*
|
|
6
|
-
* @
|
|
7
|
-
* @param {
|
|
8
|
+
* @function
|
|
9
|
+
* @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features
|
|
8
10
|
* @param {Object} [options={}] Optional Parameters
|
|
9
|
-
* @param {
|
|
10
|
-
* @returns {Feature<(Polygon|MultiPolygon)
|
|
11
|
+
* @param {GeoJsonProperties} [options.properties={}] properties to assign to output feature
|
|
12
|
+
* @returns {Feature<(Polygon|MultiPolygon)>|null} a combined polygon or multi-polygon feature, or null if there were no input polygons to combine
|
|
11
13
|
* @example
|
|
12
|
-
* var poly1 = turf.polygon([[
|
|
13
|
-
* [-82.574787, 35.594087],
|
|
14
|
-
* [-82.574787, 35.615581],
|
|
15
|
-
* [-82.545261, 35.615581],
|
|
16
|
-
* [-82.545261, 35.594087],
|
|
17
|
-
* [-82.574787, 35.594087]
|
|
18
|
-
* ]], {"fill": "#0f0"});
|
|
19
|
-
* var poly2 = turf.polygon([[
|
|
20
|
-
* [-82.560024, 35.585153],
|
|
21
|
-
* [-82.560024, 35.602602],
|
|
22
|
-
* [-82.52964, 35.602602],
|
|
23
|
-
* [-82.52964, 35.585153],
|
|
24
|
-
* [-82.560024, 35.585153]
|
|
25
|
-
* ]], {"fill": "#00f"});
|
|
26
14
|
*
|
|
27
|
-
*
|
|
15
|
+
* const poly1 = turf.polygon(
|
|
16
|
+
* [
|
|
17
|
+
* [
|
|
18
|
+
* [-82.574787, 35.594087],
|
|
19
|
+
* [-82.574787, 35.615581],
|
|
20
|
+
* [-82.545261, 35.615581],
|
|
21
|
+
* [-82.545261, 35.594087],
|
|
22
|
+
* [-82.574787, 35.594087],
|
|
23
|
+
* ],
|
|
24
|
+
* ],
|
|
25
|
+
* { fill: "#0f0" }
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* const poly2 = turf.polygon(
|
|
29
|
+
* [
|
|
30
|
+
* [
|
|
31
|
+
* [-82.560024, 35.585153],
|
|
32
|
+
* [-82.560024, 35.602602],
|
|
33
|
+
* [-82.52964, 35.602602],
|
|
34
|
+
* [-82.52964, 35.585153],
|
|
35
|
+
* [-82.560024, 35.585153],
|
|
36
|
+
* ],
|
|
37
|
+
* ],
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* const union = turf.union(turf.featureCollection([poly1, poly2]));
|
|
28
41
|
*
|
|
29
42
|
* //addToMap
|
|
30
|
-
*
|
|
43
|
+
* const addToMap = { poly1, poly2, union };
|
|
44
|
+
*
|
|
45
|
+
* poly1.properties.fill = "#0f0";
|
|
46
|
+
* poly2.properties.fill = "#00f";
|
|
47
|
+
* union.properties.stroke = "red";
|
|
48
|
+
* union.properties["stroke-width"] = 4;
|
|
49
|
+
* union.properties.fill = "transparent";
|
|
31
50
|
*/
|
|
32
51
|
declare function union<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
|
|
33
52
|
properties?: P;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// index.ts
|
|
2
|
-
import
|
|
2
|
+
import * as polyclip from "polyclip-ts";
|
|
3
3
|
import { multiPolygon, polygon } from "@turf/helpers";
|
|
4
4
|
import { geomEach } from "@turf/meta";
|
|
5
|
-
function
|
|
5
|
+
function union2(features, options = {}) {
|
|
6
6
|
const geoms = [];
|
|
7
7
|
geomEach(features, (geom) => {
|
|
8
8
|
geoms.push(geom.coordinates);
|
|
@@ -10,17 +10,14 @@ function union(features, options = {}) {
|
|
|
10
10
|
if (geoms.length < 2) {
|
|
11
11
|
throw new Error("Must have at least 2 geometries");
|
|
12
12
|
}
|
|
13
|
-
const unioned =
|
|
14
|
-
if (unioned.length === 0)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return polygon(unioned[0], options.properties);
|
|
18
|
-
else
|
|
19
|
-
return multiPolygon(unioned, options.properties);
|
|
13
|
+
const unioned = polyclip.union(geoms[0], ...geoms.slice(1));
|
|
14
|
+
if (unioned.length === 0) return null;
|
|
15
|
+
if (unioned.length === 1) return polygon(unioned[0], options.properties);
|
|
16
|
+
else return multiPolygon(unioned, options.properties);
|
|
20
17
|
}
|
|
21
|
-
var
|
|
18
|
+
var index_default = union2;
|
|
22
19
|
export {
|
|
23
|
-
|
|
24
|
-
union
|
|
20
|
+
index_default as default,
|
|
21
|
+
union2 as union
|
|
25
22
|
};
|
|
26
23
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import * as polyclip from \"polyclip-ts\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport {\n FeatureCollection,\n Feature,\n Polygon,\n MultiPolygon,\n GeoJsonProperties,\n} from \"geojson\";\n\n/**\n * Takes a collection of input polygons and returns a combined polygon. If the\n * input polygons are not contiguous, this function returns a multi-polygon\n * feature.\n *\n * @function\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features\n * @param {Object} [options={}] Optional Parameters\n * @param {GeoJsonProperties} [options.properties={}] properties to assign to output feature\n * @returns {Feature<(Polygon|MultiPolygon)>|null} a combined polygon or multi-polygon feature, or null if there were no input polygons to combine\n * @example\n *\n * const poly1 = turf.polygon(\n * [\n * [\n * [-82.574787, 35.594087],\n * [-82.574787, 35.615581],\n * [-82.545261, 35.615581],\n * [-82.545261, 35.594087],\n * [-82.574787, 35.594087],\n * ],\n * ],\n * { fill: \"#0f0\" }\n * );\n *\n * const poly2 = turf.polygon(\n * [\n * [\n * [-82.560024, 35.585153],\n * [-82.560024, 35.602602],\n * [-82.52964, 35.602602],\n * [-82.52964, 35.585153],\n * [-82.560024, 35.585153],\n * ],\n * ],\n * );\n *\n * const union = turf.union(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * const addToMap = { poly1, poly2, union };\n *\n * poly1.properties.fill = \"#0f0\";\n * poly2.properties.fill = \"#00f\";\n * union.properties.stroke = \"red\";\n * union.properties[\"stroke-width\"] = 4;\n * union.properties.fill = \"transparent\";\n */\nfunction union<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: { properties?: P } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polyclip.Geom[] = [];\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polyclip.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least 2 geometries\");\n }\n\n const unioned = polyclip.union(geoms[0], ...geoms.slice(1));\n if (unioned.length === 0) return null;\n if (unioned.length === 1) return polygon(unioned[0], options.properties);\n else return multiPolygon(unioned, options.properties);\n}\n\nexport { union };\nexport default union;\n"],"mappings":";AAAA,YAAY,cAAc;AAC1B,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AAyDzB,SAASA,OACP,UACA,UAA8B,CAAC,GACY;AAC3C,QAAM,QAAyB,CAAC;AAChC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAA4B;AAAA,EAC9C,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,UAAmB,eAAM,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AAC1D,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,MAAI,QAAQ,WAAW,EAAG,QAAO,QAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU;AAAA,MAClE,QAAO,aAAa,SAAS,QAAQ,UAAU;AACtD;AAGA,IAAO,gBAAQC;","names":["union","union"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/union",
|
|
3
|
-
"version": "7.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.3.0",
|
|
4
|
+
"description": "Combines two or more polygons into a single polygon.",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bugs": {
|
|
@@ -51,23 +51,23 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/benchmark": "^2.1.5",
|
|
54
|
-
"@types/tape": "^
|
|
54
|
+
"@types/tape": "^5.8.1",
|
|
55
55
|
"benchmark": "^2.1.4",
|
|
56
|
-
"glob": "^
|
|
56
|
+
"glob": "^11.0.2",
|
|
57
57
|
"load-json-file": "^7.0.1",
|
|
58
58
|
"npm-run-all": "^4.1.5",
|
|
59
|
-
"tape": "^5.
|
|
60
|
-
"tsup": "^8.0
|
|
61
|
-
"tsx": "^4.
|
|
62
|
-
"typescript": "^5.
|
|
63
|
-
"write-json-file": "^
|
|
59
|
+
"tape": "^5.9.0",
|
|
60
|
+
"tsup": "^8.4.0",
|
|
61
|
+
"tsx": "^4.19.4",
|
|
62
|
+
"typescript": "^5.8.3",
|
|
63
|
+
"write-json-file": "^6.0.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@turf/helpers": "
|
|
67
|
-
"@turf/meta": "
|
|
66
|
+
"@turf/helpers": "7.3.0",
|
|
67
|
+
"@turf/meta": "7.3.0",
|
|
68
68
|
"@types/geojson": "^7946.0.10",
|
|
69
|
-
"
|
|
70
|
-
"tslib": "^2.
|
|
69
|
+
"polyclip-ts": "^0.16.8",
|
|
70
|
+
"tslib": "^2.8.1"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
|
|
73
73
|
}
|