@turf/intersect 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 +14 -10
- package/dist/es/index.js +14 -11
- package/dist/js/index.d.ts +5 -6
- package/dist/js/index.js +16 -15
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
## intersect
|
|
6
6
|
|
|
7
|
-
Takes
|
|
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
|
-
|
|
10
|
+
### Parameters
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
**
|
|
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][
|
|
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.
|
|
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
|
|
2
|
-
import {
|
|
1
|
+
import { multiPolygon, polygon } from "@turf/helpers";
|
|
2
|
+
import { geomEach } from "@turf/meta";
|
|
3
3
|
import polygonClipping from "polygon-clipping";
|
|
4
4
|
/**
|
|
5
|
-
* Takes
|
|
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 {
|
|
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(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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)
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Feature, MultiPolygon, Polygon,
|
|
1
|
+
import { Feature, GeoJsonProperties, MultiPolygon, Polygon, FeatureCollection } from "geojson";
|
|
2
2
|
/**
|
|
3
|
-
* Takes
|
|
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 {
|
|
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 =
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
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 {
|
|
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(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf intersect module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"docs": "node ../../scripts/generate-readmes",
|
|
44
44
|
"test": "npm-run-all test:*",
|
|
45
45
|
"test:tape": "ts-node -r esm test.js",
|
|
46
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
46
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/tape": "*",
|
|
@@ -58,9 +58,10 @@
|
|
|
58
58
|
"write-json-file": "*"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@turf/helpers": "^
|
|
62
|
-
"@turf/
|
|
63
|
-
"polygon-clipping": "^0.15.3"
|
|
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"
|
|
64
65
|
},
|
|
65
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
66
67
|
}
|