@turf/points-within-polygon 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 +17 -13
- package/dist/es/index.js +28 -11
- package/dist/js/index.js +32 -12
- package/index.d.ts +7 -5
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
## pointsWithinPolygon
|
|
6
6
|
|
|
7
|
-
Finds [Points][1] that fall within [(Multi)Polygon(s)][
|
|
7
|
+
Finds [Points][1] or [MultiPoint][2] coordinate positions that fall within [(Multi)Polygon(s)][3].
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
* `points` **([Feature][4] | [FeatureCollection][5]<([Point][6] | [MultiPoint][7])>)** Point(s) or MultiPoint(s) as input search
|
|
12
|
+
* `polygons` **([FeatureCollection][5] | [Geometry][8] | [Feature][4]<([Polygon][9] | [MultiPolygon][10])>)** (Multi)Polygon(s) to check if points are within
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
### Examples
|
|
15
15
|
|
|
16
16
|
```javascript
|
|
17
17
|
var points = turf.points([
|
|
@@ -42,23 +42,27 @@ turf.featureEach(ptsWithin, function (currentFeature) {
|
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Returns **[FeatureCollection][
|
|
45
|
+
Returns **[FeatureCollection][5]<([Point][6] | [MultiPoint][7])>** Point(s) or MultiPoint(s) with positions that land within at least one polygon. The geometry type will match what was passsed in
|
|
46
46
|
|
|
47
47
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
48
48
|
|
|
49
|
-
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.
|
|
49
|
+
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.3
|
|
50
50
|
|
|
51
|
-
[3]: https://tools.ietf.org/html/rfc7946#section-3.
|
|
51
|
+
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
52
52
|
|
|
53
|
-
[4]: https://tools.ietf.org/html/rfc7946#section-3.
|
|
53
|
+
[4]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
54
54
|
|
|
55
|
-
[5]: https://tools.ietf.org/html/rfc7946#section-3.
|
|
55
|
+
[5]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
56
56
|
|
|
57
|
-
[6]: https://tools.ietf.org/html/rfc7946#section-3.1
|
|
57
|
+
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
58
58
|
|
|
59
|
-
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.
|
|
59
|
+
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.3
|
|
60
60
|
|
|
61
|
-
[8]: https://tools.ietf.org/html/rfc7946#section-3.1
|
|
61
|
+
[8]: https://tools.ietf.org/html/rfc7946#section-3.1
|
|
62
|
+
|
|
63
|
+
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
64
|
+
|
|
65
|
+
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.7
|
|
62
66
|
|
|
63
67
|
<!-- This file is automatically generated. Please don't edit it directly:
|
|
64
68
|
if you find an error, edit the source file (likely index.js), and re-run
|
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, point.properties || {}));
|
|
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, point.properties || {}));
|
|
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,17 +3,19 @@ import {
|
|
|
3
3
|
FeatureCollection,
|
|
4
4
|
Polygon,
|
|
5
5
|
MultiPolygon,
|
|
6
|
+
MultiPoint,
|
|
6
7
|
Point,
|
|
7
|
-
|
|
8
|
-
} from "
|
|
8
|
+
GeoJsonProperties,
|
|
9
|
+
} from "geojson";
|
|
9
10
|
|
|
10
11
|
/**
|
|
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
|
-
P =
|
|
17
|
+
P = GeoJsonProperties
|
|
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": "
|
|
3
|
+
"version": "7.0.0-alpha.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
|
},
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"docs": "node ../../scripts/generate-readmes",
|
|
44
45
|
"test": "npm-run-all test:*",
|
|
45
46
|
"test:tape": "node -r esm test.js",
|
|
46
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
47
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"benchmark": "*",
|
|
@@ -52,9 +53,9 @@
|
|
|
52
53
|
"tape": "*"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@turf/boolean-point-in-polygon": "^
|
|
56
|
-
"@turf/helpers": "^
|
|
57
|
-
"@turf/meta": "^
|
|
56
|
+
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.0",
|
|
57
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
58
|
+
"@turf/meta": "^7.0.0-alpha.0"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
60
61
|
}
|