@turf/union 6.5.0 → 7.0.0-alpha.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,16 +4,16 @@
4
4
 
5
5
  ## union
6
6
 
7
- Takes two [(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 input [(Multi)Polygon(s)][1] and returns a combined polygon. If the input polygons are not contiguous, this function returns a [MultiPolygon][2] feature.
8
8
 
9
- **Parameters**
9
+ ### Parameters
10
10
 
11
- - `polygon1` **[Feature][3]<([Polygon][4] \| [MultiPolygon][5])>** input Polygon feature
12
- - `polygon2` **[Feature][3]<([Polygon][4] \| [MultiPolygon][5])>** Polygon feature to difference from polygon1
13
- - `options` **[Object][6]** Optional Parameters (optional, default `{}`)
14
- - `options.properties` **[Object][6]** Translate Properties to output Feature (optional, default `{}`)
11
+ * `polygon1` **[Feature][3]<([Polygon][4] | [MultiPolygon][5])>** input Polygon features
12
+ * `options` **[Object][6]** Optional Parameters (optional, default `{}`)
15
13
 
16
- **Examples**
14
+ * `options.properties` **[Object][6]** Translate Properties to output Feature (optional, default `{}`)
15
+
16
+ ### Examples
17
17
 
18
18
  ```javascript
19
19
  var poly1 = turf.polygon([[
@@ -31,13 +31,13 @@ var poly2 = turf.polygon([[
31
31
  [-82.560024, 35.585153]
32
32
  ]], {"fill": "#00f"});
33
33
 
34
- var union = turf.union(poly1, poly2);
34
+ var union = turf.union(turf.featureCollection([poly1, poly2]));
35
35
 
36
36
  //addToMap
37
37
  var addToMap = [poly1, poly2, union];
38
38
  ```
39
39
 
40
- Returns **[Feature][3]&lt;([Polygon][4] \| [MultiPolygon][5])>** a combined [Polygon][1] or [MultiPolygon][2] feature
40
+ Returns **[Feature][3]<([Polygon][4] | [MultiPolygon][5])>** a combined [Polygon][1] or [MultiPolygon][2] feature, or null if the inputs are empty
41
41
 
42
42
  [1]: https://tools.ietf.org/html/rfc7946#section-3.1.6
43
43
 
package/dist/es/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import polygonClipping from "polygon-clipping";
2
- import { getGeom } from "@turf/invariant";
3
2
  import { multiPolygon, polygon } from "@turf/helpers";
3
+ import { geomEach } from "@turf/meta";
4
4
  /**
5
- * Takes two {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
5
+ * 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.
6
6
  *
7
7
  * @name union
8
- * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature
9
- * @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1
8
+ * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features
10
9
  * @param {Object} [options={}] Optional Parameters
11
10
  * @param {Object} [options.properties={}] Translate Properties to output Feature
12
11
  * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty
@@ -26,16 +25,20 @@ import { multiPolygon, polygon } from "@turf/helpers";
26
25
  * [-82.560024, 35.585153]
27
26
  * ]], {"fill": "#00f"});
28
27
  *
29
- * var union = turf.union(poly1, poly2);
28
+ * var union = turf.union(turf.featureCollection([poly1, poly2]));
30
29
  *
31
30
  * //addToMap
32
31
  * var addToMap = [poly1, poly2, union];
33
32
  */
34
- function union(poly1, poly2, options) {
35
- if (options === void 0) { options = {}; }
36
- var geom1 = getGeom(poly1);
37
- var geom2 = getGeom(poly2);
38
- var unioned = polygonClipping.union(geom1.coordinates, geom2.coordinates);
33
+ function union(features, options = {}) {
34
+ const geoms = [];
35
+ geomEach(features, (geom) => {
36
+ geoms.push(geom.coordinates);
37
+ });
38
+ if (geoms.length < 2) {
39
+ throw new Error("Must have at least 2 geometries");
40
+ }
41
+ const unioned = polygonClipping.union(geoms[0], ...geoms.slice(1));
39
42
  if (unioned.length === 0)
40
43
  return null;
41
44
  if (unioned.length === 1)
@@ -1,10 +1,9 @@
1
- import { Feature, Polygon, MultiPolygon, Properties } from "@turf/helpers";
1
+ import { FeatureCollection, Feature, Polygon, MultiPolygon, GeoJsonProperties } from "geojson";
2
2
  /**
3
- * Takes two {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
3
+ * 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
4
  *
5
5
  * @name union
6
- * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature
7
- * @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1
6
+ * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features
8
7
  * @param {Object} [options={}] Optional Parameters
9
8
  * @param {Object} [options.properties={}] Translate Properties to output Feature
10
9
  * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty
@@ -24,12 +23,12 @@ import { Feature, Polygon, MultiPolygon, Properties } from "@turf/helpers";
24
23
  * [-82.560024, 35.585153]
25
24
  * ]], {"fill": "#00f"});
26
25
  *
27
- * var union = turf.union(poly1, poly2);
26
+ * var union = turf.union(turf.featureCollection([poly1, poly2]));
28
27
  *
29
28
  * //addToMap
30
29
  * var addToMap = [poly1, poly2, union];
31
30
  */
32
- declare function union<P = Properties>(poly1: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, poly2: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, options?: {
31
+ declare function union<P = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
33
32
  properties?: P;
34
33
  }): Feature<Polygon | MultiPolygon, P> | null;
35
34
  export default union;
package/dist/js/index.js CHANGED
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var polygon_clipping_1 = __importDefault(require("polygon-clipping"));
7
- var invariant_1 = require("@turf/invariant");
8
- var helpers_1 = require("@turf/helpers");
3
+ const tslib_1 = require("tslib");
4
+ const polygon_clipping_1 = tslib_1.__importDefault(require("polygon-clipping"));
5
+ const helpers_1 = require("@turf/helpers");
6
+ const meta_1 = require("@turf/meta");
9
7
  /**
10
- * Takes two {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
8
+ * 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.
11
9
  *
12
10
  * @name union
13
- * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature
14
- * @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1
11
+ * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features
15
12
  * @param {Object} [options={}] Optional Parameters
16
13
  * @param {Object} [options.properties={}] Translate Properties to output Feature
17
14
  * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty
@@ -31,16 +28,20 @@ var helpers_1 = require("@turf/helpers");
31
28
  * [-82.560024, 35.585153]
32
29
  * ]], {"fill": "#00f"});
33
30
  *
34
- * var union = turf.union(poly1, poly2);
31
+ * var union = turf.union(turf.featureCollection([poly1, poly2]));
35
32
  *
36
33
  * //addToMap
37
34
  * var addToMap = [poly1, poly2, union];
38
35
  */
39
- function union(poly1, poly2, options) {
40
- if (options === void 0) { options = {}; }
41
- var geom1 = invariant_1.getGeom(poly1);
42
- var geom2 = invariant_1.getGeom(poly2);
43
- var unioned = polygon_clipping_1.default.union(geom1.coordinates, geom2.coordinates);
36
+ function union(features, options = {}) {
37
+ const geoms = [];
38
+ meta_1.geomEach(features, (geom) => {
39
+ geoms.push(geom.coordinates);
40
+ });
41
+ if (geoms.length < 2) {
42
+ throw new Error("Must have at least 2 geometries");
43
+ }
44
+ const unioned = polygon_clipping_1.default.union(geoms[0], ...geoms.slice(1));
44
45
  if (unioned.length === 0)
45
46
  return null;
46
47
  if (unioned.length === 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/union",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf union module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -42,10 +42,9 @@
42
42
  "docs": "node ../../scripts/generate-readmes",
43
43
  "test": "npm-run-all test:*",
44
44
  "test:tape": "ts-node -r esm test.js",
45
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
45
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
46
46
  },
47
47
  "devDependencies": {
48
- "@turf/combine": "^6.5.0",
49
48
  "@types/tape": "*",
50
49
  "benchmark": "*",
51
50
  "glob": "*",
@@ -58,9 +57,10 @@
58
57
  "write-json-file": "*"
59
58
  },
60
59
  "dependencies": {
61
- "@turf/helpers": "^6.5.0",
62
- "@turf/invariant": "^6.5.0",
63
- "polygon-clipping": "^0.15.3"
60
+ "@turf/helpers": "^7.0.0-alpha.0",
61
+ "@turf/meta": "^7.0.0-alpha.0",
62
+ "polygon-clipping": "^0.15.3",
63
+ "tslib": "^2.3.0"
64
64
  },
65
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
65
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
66
66
  }