@turf/points-within-polygon 6.4.0 → 6.5.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/dist/es/index.js +28 -11
- package/dist/js/index.js +32 -12
- package/index.d.ts +4 -2
- package/package.json +6 -5
package/dist/es/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import pointInPolygon from '@turf/boolean-point-in-polygon';
|
|
2
|
-
import { featureCollection } from '@turf/helpers';
|
|
3
|
-
import { geomEach,
|
|
2
|
+
import { multiPoint, featureCollection } from '@turf/helpers';
|
|
3
|
+
import { featureEach, geomEach, coordEach } from '@turf/meta';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Finds {@link Points} that fall within {@link (Multi)Polygon(s)}.
|
|
6
|
+
* Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.
|
|
7
7
|
*
|
|
8
8
|
* @name pointsWithinPolygon
|
|
9
|
-
* @param {Feature|FeatureCollection<Point>} points
|
|
10
|
-
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons
|
|
11
|
-
* @returns {FeatureCollection<Point>}
|
|
9
|
+
* @param {Feature|FeatureCollection<Point|MultiPoint>} points Point(s) or MultiPoint(s) as input search
|
|
10
|
+
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons (Multi)Polygon(s) to check if points are within
|
|
11
|
+
* @returns {FeatureCollection<Point|MultiPoint>} Point(s) or MultiPoint(s) with positions that land within at least one polygon. The geometry type will match what was passsed in
|
|
12
12
|
* @example
|
|
13
13
|
* var points = turf.points([
|
|
14
14
|
* [-46.6318, -23.5523],
|
|
@@ -41,11 +41,28 @@ function pointsWithinPolygon(points, polygons) {
|
|
|
41
41
|
var results = [];
|
|
42
42
|
featureEach(points, function (point) {
|
|
43
43
|
var contained = false;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (point.geometry.type === "Point") {
|
|
45
|
+
geomEach(polygons, function (polygon) {
|
|
46
|
+
if (pointInPolygon(point, polygon)) contained = true;
|
|
47
|
+
});
|
|
48
|
+
if (contained) {
|
|
49
|
+
results.push(point);
|
|
50
|
+
}
|
|
51
|
+
} else if (point.geometry.type === "MultiPoint") {
|
|
52
|
+
var pointsWithin = [];
|
|
53
|
+
geomEach(polygons, function (polygon) {
|
|
54
|
+
coordEach(point, function (pointCoord) {
|
|
55
|
+
if (pointInPolygon(pointCoord, polygon)) {
|
|
56
|
+
contained = true;
|
|
57
|
+
pointsWithin.push(pointCoord);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
if (contained) {
|
|
62
|
+
results.push(multiPoint(pointsWithin));
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error("Input geometry must be a Point or MultiPoint");
|
|
49
66
|
}
|
|
50
67
|
});
|
|
51
68
|
return featureCollection(results);
|
package/dist/js/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var pointInPolygon = _interopDefault(require('@turf/boolean-point-in-polygon'));
|
|
3
|
+
var pointInPolygon = require('@turf/boolean-point-in-polygon');
|
|
6
4
|
var helpers = require('@turf/helpers');
|
|
7
5
|
var meta = require('@turf/meta');
|
|
8
6
|
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var pointInPolygon__default = /*#__PURE__*/_interopDefaultLegacy(pointInPolygon);
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
|
-
* Finds {@link Points} that fall within {@link (Multi)Polygon(s)}.
|
|
12
|
+
* Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.
|
|
11
13
|
*
|
|
12
14
|
* @name pointsWithinPolygon
|
|
13
|
-
* @param {Feature|FeatureCollection<Point>} points
|
|
14
|
-
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons
|
|
15
|
-
* @returns {FeatureCollection<Point>}
|
|
15
|
+
* @param {Feature|FeatureCollection<Point|MultiPoint>} points Point(s) or MultiPoint(s) as input search
|
|
16
|
+
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons (Multi)Polygon(s) to check if points are within
|
|
17
|
+
* @returns {FeatureCollection<Point|MultiPoint>} Point(s) or MultiPoint(s) with positions that land within at least one polygon. The geometry type will match what was passsed in
|
|
16
18
|
* @example
|
|
17
19
|
* var points = turf.points([
|
|
18
20
|
* [-46.6318, -23.5523],
|
|
@@ -45,14 +47,32 @@ function pointsWithinPolygon(points, polygons) {
|
|
|
45
47
|
var results = [];
|
|
46
48
|
meta.featureEach(points, function (point) {
|
|
47
49
|
var contained = false;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (point.geometry.type === "Point") {
|
|
51
|
+
meta.geomEach(polygons, function (polygon) {
|
|
52
|
+
if (pointInPolygon__default['default'](point, polygon)) contained = true;
|
|
53
|
+
});
|
|
54
|
+
if (contained) {
|
|
55
|
+
results.push(point);
|
|
56
|
+
}
|
|
57
|
+
} else if (point.geometry.type === "MultiPoint") {
|
|
58
|
+
var pointsWithin = [];
|
|
59
|
+
meta.geomEach(polygons, function (polygon) {
|
|
60
|
+
meta.coordEach(point, function (pointCoord) {
|
|
61
|
+
if (pointInPolygon__default['default'](pointCoord, polygon)) {
|
|
62
|
+
contained = true;
|
|
63
|
+
pointsWithin.push(pointCoord);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
if (contained) {
|
|
68
|
+
results.push(helpers.multiPoint(pointsWithin));
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
throw new Error("Input geometry must be a Point or MultiPoint");
|
|
53
72
|
}
|
|
54
73
|
});
|
|
55
74
|
return helpers.featureCollection(results);
|
|
56
75
|
}
|
|
57
76
|
|
|
58
77
|
module.exports = pointsWithinPolygon;
|
|
78
|
+
module.exports.default = pointsWithinPolygon;
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
FeatureCollection,
|
|
4
4
|
Polygon,
|
|
5
5
|
MultiPolygon,
|
|
6
|
+
MultiPoint,
|
|
6
7
|
Point,
|
|
7
8
|
Properties,
|
|
8
9
|
} from "@turf/helpers";
|
|
@@ -11,9 +12,10 @@ import {
|
|
|
11
12
|
* http://turfjs.org/docs/#pointswithinpolygon
|
|
12
13
|
*/
|
|
13
14
|
export default function pointsWithinPolygon<
|
|
15
|
+
F extends Point | MultiPoint,
|
|
14
16
|
G extends Polygon | MultiPolygon,
|
|
15
17
|
P = Properties
|
|
16
18
|
>(
|
|
17
|
-
points: Feature<
|
|
19
|
+
points: Feature<F, P> | FeatureCollection<F, P>,
|
|
18
20
|
polygons: Feature<G> | FeatureCollection<G> | G
|
|
19
|
-
): FeatureCollection<
|
|
21
|
+
): FeatureCollection<F, P>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/points-within-polygon",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "turf points-within-polygon 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
|
},
|
|
@@ -52,9 +53,9 @@
|
|
|
52
53
|
"tape": "*"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@turf/boolean-point-in-polygon": "^6.
|
|
56
|
-
"@turf/helpers": "^6.
|
|
57
|
-
"@turf/meta": "^6.
|
|
56
|
+
"@turf/boolean-point-in-polygon": "^6.5.0",
|
|
57
|
+
"@turf/helpers": "^6.5.0",
|
|
58
|
+
"@turf/meta": "^6.5.0"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
|
|
60
61
|
}
|