@turf/intersect 6.4.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,17 @@
4
4
 
5
5
  ## intersect
6
6
 
7
- Takes two [polygon][1] or [multi-polygon][2] geometries and finds their polygonal intersection. If they don't intersect, returns null.
7
+ Takes [polygon][1] or [multi-polygon][2] geometries and
8
+ finds their polygonal intersection. If they don't intersect, returns null.
8
9
 
9
- **Parameters**
10
+ ### Parameters
10
11
 
11
- - `poly1` **[Feature][3]<([Polygon][4] \| [MultiPolygon][5])>** the first polygon or multipolygon
12
- - `poly2` **[Feature][3]<([Polygon][4] \| [MultiPolygon][5])>** the second polygon or multipolygon
13
- - `options` **[Object][6]** Optional Parameters (optional, default `{}`)
14
- - `options.properties` **[Object][6]** Translate GeoJSON Properties to Feature (optional, default `{}`)
12
+ * `features` **[FeatureCollection][3]<([Polygon][4] | [MultiPolygon][5])>** the features to intersect
13
+ * `options` **[Object][6]** Optional Parameters (optional, default `{}`)
15
14
 
16
- **Examples**
15
+ * `options.properties` **[Object][6]** Translate GeoJSON Properties to Feature (optional, default `{}`)
16
+
17
+ ### Examples
17
18
 
18
19
  ```javascript
19
20
  var poly1 = turf.polygon([[
@@ -35,19 +36,20 @@ var poly2 = turf.polygon([[
35
36
  [-122.520217, 45.535693]
36
37
  ]]);
37
38
 
38
- var intersection = turf.intersect(poly1, poly2);
39
+ var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
39
40
 
40
41
  //addToMap
41
42
  var addToMap = [poly1, poly2, intersection];
42
43
  ```
43
44
 
44
- Returns **([Feature][3] | null)** returns a feature representing the area they share (either a [Polygon][1] or [MultiPolygon][2]). If they do not share any area, returns `null`.
45
+ Returns **([Feature][7] | null)** returns a feature representing the area they share (either a [Polygon][1] or
46
+ [MultiPolygon][2]). If they do not share any area, returns `null`.
45
47
 
46
48
  [1]: https://tools.ietf.org/html/rfc7946#section-3.1.6
47
49
 
48
50
  [2]: https://tools.ietf.org/html/rfc7946#section-3.1.7
49
51
 
50
- [3]: https://tools.ietf.org/html/rfc7946#section-3.2
52
+ [3]: https://tools.ietf.org/html/rfc7946#section-3.3
51
53
 
52
54
  [4]: https://tools.ietf.org/html/rfc7946#section-3.1.6
53
55
 
@@ -55,6 +57,8 @@ Returns **([Feature][3] | null)** returns a feature representing the area they s
55
57
 
56
58
  [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
57
59
 
60
+ [7]: https://tools.ietf.org/html/rfc7946#section-3.2
61
+
58
62
  <!-- This file is automatically generated. Please don't edit it directly:
59
63
  if you find an error, edit the source file (likely index.js), and re-run
60
64
  ./scripts/generate-readmes in the turf project. -->
package/dist/es/index.js CHANGED
@@ -1,13 +1,12 @@
1
- import { multiPolygon, polygon, } from "@turf/helpers";
2
- import { getGeom } from "@turf/invariant";
1
+ import { multiPolygon, polygon } from "@turf/helpers";
2
+ import { geomEach } from "@turf/meta";
3
3
  import polygonClipping from "polygon-clipping";
4
4
  /**
5
- * Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
5
+ * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
6
6
  * finds their polygonal intersection. If they don't intersect, returns null.
7
7
  *
8
8
  * @name intersect
9
- * @param {Feature<Polygon | MultiPolygon>} poly1 the first polygon or multipolygon
10
- * @param {Feature<Polygon | MultiPolygon>} poly2 the second polygon or multipolygon
9
+ * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
11
10
  * @param {Object} [options={}] Optional Parameters
12
11
  * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
13
12
  * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or
@@ -32,16 +31,20 @@ import polygonClipping from "polygon-clipping";
32
31
  * [-122.520217, 45.535693]
33
32
  * ]]);
34
33
  *
35
- * var intersection = turf.intersect(poly1, poly2);
34
+ * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
36
35
  *
37
36
  * //addToMap
38
37
  * var addToMap = [poly1, poly2, intersection];
39
38
  */
40
- export default function intersect(poly1, poly2, options) {
41
- if (options === void 0) { options = {}; }
42
- var geom1 = getGeom(poly1);
43
- var geom2 = getGeom(poly2);
44
- var intersection = polygonClipping.intersection(geom1.coordinates, geom2.coordinates);
39
+ export default function intersect(features, options = {}) {
40
+ const geoms = [];
41
+ geomEach(features, (geom) => {
42
+ geoms.push(geom.coordinates);
43
+ });
44
+ if (geoms.length < 2) {
45
+ throw new Error("Must specify at least 2 geometries");
46
+ }
47
+ const intersection = polygonClipping.intersection(geoms[0], ...geoms.slice(1));
45
48
  if (intersection.length === 0)
46
49
  return null;
47
50
  if (intersection.length === 1)
@@ -1,11 +1,10 @@
1
- import { Feature, MultiPolygon, Polygon, Properties } from "@turf/helpers";
1
+ import { Feature, GeoJsonProperties, MultiPolygon, Polygon, FeatureCollection } from "geojson";
2
2
  /**
3
- * Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
3
+ * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
4
4
  * finds their polygonal intersection. If they don't intersect, returns null.
5
5
  *
6
6
  * @name intersect
7
- * @param {Feature<Polygon | MultiPolygon>} poly1 the first polygon or multipolygon
8
- * @param {Feature<Polygon | MultiPolygon>} poly2 the second polygon or multipolygon
7
+ * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
9
8
  * @param {Object} [options={}] Optional Parameters
10
9
  * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
11
10
  * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or
@@ -30,11 +29,11 @@ import { Feature, MultiPolygon, Polygon, Properties } from "@turf/helpers";
30
29
  * [-122.520217, 45.535693]
31
30
  * ]]);
32
31
  *
33
- * var intersection = turf.intersect(poly1, poly2);
32
+ * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
34
33
  *
35
34
  * //addToMap
36
35
  * var addToMap = [poly1, poly2, intersection];
37
36
  */
38
- export default function intersect<P = Properties>(poly1: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, poly2: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, options?: {
37
+ export default function intersect<P = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
39
38
  properties?: P;
40
39
  }): Feature<Polygon | MultiPolygon, P> | null;
package/dist/js/index.js CHANGED
@@ -1,18 +1,15 @@
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 helpers_1 = require("@turf/helpers");
7
- var invariant_1 = require("@turf/invariant");
8
- var polygon_clipping_1 = __importDefault(require("polygon-clipping"));
3
+ const tslib_1 = require("tslib");
4
+ const helpers_1 = require("@turf/helpers");
5
+ const meta_1 = require("@turf/meta");
6
+ const polygon_clipping_1 = tslib_1.__importDefault(require("polygon-clipping"));
9
7
  /**
10
- * Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
8
+ * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
11
9
  * finds their polygonal intersection. If they don't intersect, returns null.
12
10
  *
13
11
  * @name intersect
14
- * @param {Feature<Polygon | MultiPolygon>} poly1 the first polygon or multipolygon
15
- * @param {Feature<Polygon | MultiPolygon>} poly2 the second polygon or multipolygon
12
+ * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
16
13
  * @param {Object} [options={}] Optional Parameters
17
14
  * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
18
15
  * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or
@@ -37,16 +34,20 @@ var polygon_clipping_1 = __importDefault(require("polygon-clipping"));
37
34
  * [-122.520217, 45.535693]
38
35
  * ]]);
39
36
  *
40
- * var intersection = turf.intersect(poly1, poly2);
37
+ * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
41
38
  *
42
39
  * //addToMap
43
40
  * var addToMap = [poly1, poly2, intersection];
44
41
  */
45
- function intersect(poly1, poly2, options) {
46
- if (options === void 0) { options = {}; }
47
- var geom1 = invariant_1.getGeom(poly1);
48
- var geom2 = invariant_1.getGeom(poly2);
49
- var intersection = polygon_clipping_1.default.intersection(geom1.coordinates, geom2.coordinates);
42
+ function intersect(features, options = {}) {
43
+ const geoms = [];
44
+ meta_1.geomEach(features, (geom) => {
45
+ geoms.push(geom.coordinates);
46
+ });
47
+ if (geoms.length < 2) {
48
+ throw new Error("Must specify at least 2 geometries");
49
+ }
50
+ const intersection = polygon_clipping_1.default.intersection(geoms[0], ...geoms.slice(1));
50
51
  if (intersection.length === 0)
51
52
  return null;
52
53
  if (intersection.length === 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/intersect",
3
- "version": "6.4.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf intersect module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -12,6 +12,7 @@
12
12
  "type": "git",
13
13
  "url": "git://github.com/Turfjs/turf.git"
14
14
  },
15
+ "funding": "https://opencollective.com/turf",
15
16
  "publishConfig": {
16
17
  "access": "public"
17
18
  },
@@ -42,7 +43,7 @@
42
43
  "docs": "node ../../scripts/generate-readmes",
43
44
  "test": "npm-run-all test:*",
44
45
  "test:tape": "ts-node -r esm test.js",
45
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
46
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@types/tape": "*",
@@ -57,9 +58,10 @@
57
58
  "write-json-file": "*"
58
59
  },
59
60
  "dependencies": {
60
- "@turf/helpers": "^6.4.0",
61
- "@turf/invariant": "^6.4.0",
62
- "polygon-clipping": "^0.15.2"
61
+ "@turf/helpers": "^7.0.0-alpha.0",
62
+ "@turf/meta": "^7.0.0-alpha.0",
63
+ "polygon-clipping": "^0.15.3",
64
+ "tslib": "^2.3.0"
63
65
  },
64
- "gitHead": "1e62773cfc88c627cca8effcb5c14cfb65a905ac"
66
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
65
67
  }