@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 CHANGED
@@ -4,49 +4,69 @@
4
4
 
5
5
  ## union
6
6
 
7
- Takes input [(Multi)Polygon(s)][1] and returns a combined polygon. If the input polygons are not contiguous, this function returns a [MultiPolygon][2] feature.
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
- * `polygon1` **[Feature][3]<([Polygon][1] | [MultiPolygon][2])>** input Polygon features
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` **[Object][4]** Translate Properties to output Feature (optional, default `{}`)
16
+ * `options.properties` **[GeoJsonProperties][5]** properties to assign to output feature (optional, default `{}`)
15
17
 
16
18
  ### Examples
17
19
 
18
20
  ```javascript
19
- var poly1 = turf.polygon([[
20
- [-82.574787, 35.594087],
21
- [-82.574787, 35.615581],
22
- [-82.545261, 35.615581],
23
- [-82.545261, 35.594087],
24
- [-82.574787, 35.594087]
25
- ]], {"fill": "#0f0"});
26
- var poly2 = turf.polygon([[
27
- [-82.560024, 35.585153],
28
- [-82.560024, 35.602602],
29
- [-82.52964, 35.602602],
30
- [-82.52964, 35.585153],
31
- [-82.560024, 35.585153]
32
- ]], {"fill": "#00f"});
33
-
34
- var union = turf.union(turf.featureCollection([poly1, poly2]));
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
- var addToMap = [poly1, poly2, union];
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][3]<([Polygon][1] | [MultiPolygon][2])>** a combined [Polygon][1] or [MultiPolygon][2] feature, or null if the inputs are empty
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.1.6
60
+ [1]: https://tools.ietf.org/html/rfc7946#section-3.3
43
61
 
44
- [2]: https://tools.ietf.org/html/rfc7946#section-3.1.7
62
+ [2]: https://tools.ietf.org/html/rfc7946#section-3.1.6
45
63
 
46
- [3]: https://tools.ietf.org/html/rfc7946#section-3.2
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
  ---
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
2
- var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
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 union(features, options = {}) {
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 = _polygonclipping2.default.union(geoms[0], ...geoms.slice(1));
14
- if (unioned.length === 0)
15
- return null;
16
- if (unioned.length === 1)
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 turf_union_default = union;
18
+ var index_default = union2;
22
19
 
23
20
 
24
21
 
25
- exports.default = turf_union_default; exports.union = union;
22
+ exports.default = index_default; exports.union = union2;
26
23
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAAA,OAAO,qBAAqB;AAC5B,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AAsCzB,SAAS,MACP,UACA,UAA8B,CAAC,GACY;AAC3C,QAAM,QAAgC,CAAC;AACvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,UAAU,gBAAgB,MAAM,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AACjE,MAAI,QAAQ,WAAW;AAAG,WAAO;AACjC,MAAI,QAAQ,WAAW;AAAG,WAAO,QAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU;AAAA;AAClE,WAAO,aAAa,SAAS,QAAQ,UAAU;AACtD;AAGA,IAAO,qBAAQ","sourcesContent":["import polygonClipping from \"polygon-clipping\";\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 input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.\n *\n * @name union\n * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate Properties to output Feature\n * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty\n * @example\n * var poly1 = turf.polygon([[\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 * ]], {\"fill\": \"#0f0\"});\n * var poly2 = turf.polygon([[\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 * ]], {\"fill\": \"#00f\"});\n *\n * var union = turf.union(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, union];\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: polygonClipping.Geom[] = [];\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least 2 geometries\");\n }\n\n const unioned = polygonClipping.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"]}
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"]}
@@ -1,33 +1,52 @@
1
1
  import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
2
2
 
3
3
  /**
4
- * Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
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
- * @name union
7
- * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features
8
+ * @function
9
+ * @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features
8
10
  * @param {Object} [options={}] Optional Parameters
9
- * @param {Object} [options.properties={}] Translate Properties to output Feature
10
- * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty
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
- * var union = turf.union(turf.featureCollection([poly1, poly2]));
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
- * var addToMap = [poly1, poly2, union];
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;
@@ -1,33 +1,52 @@
1
1
  import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
2
2
 
3
3
  /**
4
- * Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
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
- * @name union
7
- * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features
8
+ * @function
9
+ * @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features
8
10
  * @param {Object} [options={}] Optional Parameters
9
- * @param {Object} [options.properties={}] Translate Properties to output Feature
10
- * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty
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
- * var union = turf.union(turf.featureCollection([poly1, poly2]));
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
- * var addToMap = [poly1, poly2, union];
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 polygonClipping from "polygon-clipping";
2
+ import * as polyclip from "polyclip-ts";
3
3
  import { multiPolygon, polygon } from "@turf/helpers";
4
4
  import { geomEach } from "@turf/meta";
5
- function union(features, options = {}) {
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 = polygonClipping.union(geoms[0], ...geoms.slice(1));
14
- if (unioned.length === 0)
15
- return null;
16
- if (unioned.length === 1)
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 turf_union_default = union;
18
+ var index_default = union2;
22
19
  export {
23
- turf_union_default as default,
24
- union
20
+ index_default as default,
21
+ union2 as union
25
22
  };
26
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"sourcesContent":["import polygonClipping from \"polygon-clipping\";\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 input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.\n *\n * @name union\n * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate Properties to output Feature\n * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty\n * @example\n * var poly1 = turf.polygon([[\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 * ]], {\"fill\": \"#0f0\"});\n * var poly2 = turf.polygon([[\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 * ]], {\"fill\": \"#00f\"});\n *\n * var union = turf.union(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, union];\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: polygonClipping.Geom[] = [];\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least 2 geometries\");\n }\n\n const unioned = polygonClipping.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,OAAO,qBAAqB;AAC5B,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AAsCzB,SAAS,MACP,UACA,UAA8B,CAAC,GACY;AAC3C,QAAM,QAAgC,CAAC;AACvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,UAAU,gBAAgB,MAAM,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AACjE,MAAI,QAAQ,WAAW;AAAG,WAAO;AACjC,MAAI,QAAQ,WAAW;AAAG,WAAO,QAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU;AAAA;AAClE,WAAO,aAAa,SAAS,QAAQ,UAAU;AACtD;AAGA,IAAO,qBAAQ;","names":[]}
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.1.0",
4
- "description": "turf union module",
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": "^4.2.32",
54
+ "@types/tape": "^5.8.1",
55
55
  "benchmark": "^2.1.4",
56
- "glob": "^10.3.10",
56
+ "glob": "^11.0.2",
57
57
  "load-json-file": "^7.0.1",
58
58
  "npm-run-all": "^4.1.5",
59
- "tape": "^5.7.2",
60
- "tsup": "^8.0.1",
61
- "tsx": "^4.6.2",
62
- "typescript": "^5.2.2",
63
- "write-json-file": "^5.0.0"
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": "^7.1.0",
67
- "@turf/meta": "^7.1.0",
66
+ "@turf/helpers": "7.3.0",
67
+ "@turf/meta": "7.3.0",
68
68
  "@types/geojson": "^7946.0.10",
69
- "polygon-clipping": "^0.15.3",
70
- "tslib": "^2.6.2"
69
+ "polyclip-ts": "^0.16.8",
70
+ "tslib": "^2.8.1"
71
71
  },
72
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
72
+ "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
73
73
  }