@turf/points-within-polygon 7.0.0-alpha.1 → 7.0.0-alpha.110
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 +4 -9
- package/dist/cjs/index.cjs +48 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{es/index.js → cjs/index.d.ts} +3 -34
- package/dist/esm/index.d.mts +40 -0
- package/dist/esm/index.mjs +48 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +32 -23
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -78
- package/index.d.ts +0 -21
package/README.md
CHANGED
|
@@ -64,26 +64,21 @@ Returns **[FeatureCollection][5]<([Point][6] | [MultiPoint][7])>** Point(s) or M
|
|
|
64
64
|
|
|
65
65
|
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.7
|
|
66
66
|
|
|
67
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
68
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
69
|
-
./scripts/generate-readmes in the turf project. -->
|
|
67
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
70
68
|
|
|
71
69
|
---
|
|
72
70
|
|
|
73
|
-
This module is part of the [Turfjs project](
|
|
74
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
75
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
76
|
-
PRs and issues.
|
|
71
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
77
72
|
|
|
78
73
|
### Installation
|
|
79
74
|
|
|
80
|
-
Install this module individually:
|
|
75
|
+
Install this single module individually:
|
|
81
76
|
|
|
82
77
|
```sh
|
|
83
78
|
$ npm install @turf/points-within-polygon
|
|
84
79
|
```
|
|
85
80
|
|
|
86
|
-
Or install the
|
|
81
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
87
82
|
|
|
88
83
|
```sh
|
|
89
84
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
|
|
6
|
+
var _helpers = require('@turf/helpers');
|
|
7
|
+
var _meta = require('@turf/meta');
|
|
8
|
+
function pointsWithinPolygon(points, polygons) {
|
|
9
|
+
const results = [];
|
|
10
|
+
_meta.featureEach.call(void 0, points, function(point) {
|
|
11
|
+
let contained = false;
|
|
12
|
+
if (point.geometry.type === "Point") {
|
|
13
|
+
_meta.geomEach.call(void 0, polygons, function(polygon) {
|
|
14
|
+
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, point, polygon)) {
|
|
15
|
+
contained = true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (contained) {
|
|
19
|
+
results.push(point);
|
|
20
|
+
}
|
|
21
|
+
} else if (point.geometry.type === "MultiPoint") {
|
|
22
|
+
var pointsWithin = [];
|
|
23
|
+
_meta.geomEach.call(void 0, polygons, function(polygon) {
|
|
24
|
+
_meta.coordEach.call(void 0, point, function(pointCoord) {
|
|
25
|
+
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, pointCoord, polygon)) {
|
|
26
|
+
contained = true;
|
|
27
|
+
pointsWithin.push(pointCoord);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
if (contained) {
|
|
32
|
+
results.push(
|
|
33
|
+
_helpers.multiPoint.call(void 0, pointsWithin, point.properties)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
throw new Error("Input geometry must be a Point or MultiPoint");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return _helpers.featureCollection.call(void 0, results);
|
|
41
|
+
}
|
|
42
|
+
__name(pointsWithinPolygon, "pointsWithinPolygon");
|
|
43
|
+
var turf_points_within_polygon_default = pointsWithinPolygon;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
exports.default = turf_points_within_polygon_default; exports.pointsWithinPolygon = pointsWithinPolygon;
|
|
48
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAUA,SAAS,yBAAyB,sBAAsB;AACxD,SAAS,mBAAmB,kBAAkB;AAC9C,SAAS,UAAU,aAAa,iBAAiB;AAqCjD,SAAS,oBAIP,QAGA,UAC0C;AAC1C,QAAM,UAA4C,CAAC;AACnD,cAAY,QAAQ,SAAU,OAAO;AACnC,QAAI,YAAY;AAChB,QAAI,MAAM,SAAS,SAAS,SAAS;AACnC,eAAS,UAAU,SAAU,SAAS;AACpC,YAAI,eAAe,OAA4B,OAAO,GAAG;AACvD,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,UAAI,WAAW;AACb,gBAAQ,KAAK,KAAK;AAAA,MACpB;AAAA,IACF,WAAW,MAAM,SAAS,SAAS,cAAc;AAC/C,UAAI,eAA2B,CAAC;AAChC,eAAS,UAAU,SAAU,SAAS;AACpC,kBAAU,OAA8B,SAAU,YAAY;AAC5D,cAAI,eAAe,YAAY,OAAO,GAAG;AACvC,wBAAY;AACZ,yBAAa,KAAK,UAAU;AAAA,UAC9B;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AACD,UAAI,WAAW;AACb,gBAAQ;AAAA,UACN,WAAW,cAAc,MAAM,UAAU;AAAA,QAC3C;AAAA,MACF;AAAA,IACF,OAAO;AACL,YAAM,IAAI,MAAM,8CAA8C;AAAA,IAChE;AAAA,EACF,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAzCS;AA4CT,IAAO,qCAAQ","sourcesContent":["import type {\n Feature,\n FeatureCollection,\n Polygon,\n MultiPolygon,\n MultiPoint,\n Point,\n GeoJsonProperties,\n Position,\n} from \"geojson\";\nimport { booleanPointInPolygon as pointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { featureCollection, multiPoint } from \"@turf/helpers\";\nimport { geomEach, featureEach, coordEach } from \"@turf/meta\";\n\n/**\n * Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.\n *\n * @name pointsWithinPolygon\n * @param {Feature|FeatureCollection<Point|MultiPoint>} points Point(s) or MultiPoint(s) as input search\n * @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons (Multi)Polygon(s) to check if points are within\n * @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\n * @example\n * var points = turf.points([\n * [-46.6318, -23.5523],\n * [-46.6246, -23.5325],\n * [-46.6062, -23.5513],\n * [-46.663, -23.554],\n * [-46.643, -23.557]\n * ]);\n *\n * var searchWithin = turf.polygon([[\n * [-46.653,-23.543],\n * [-46.634,-23.5346],\n * [-46.613,-23.543],\n * [-46.614,-23.559],\n * [-46.631,-23.567],\n * [-46.653,-23.560],\n * [-46.653,-23.543]\n * ]]);\n *\n * var ptsWithin = turf.pointsWithinPolygon(points, searchWithin);\n *\n * //addToMap\n * var addToMap = [points, searchWithin, ptsWithin]\n * turf.featureEach(ptsWithin, function (currentFeature) {\n * currentFeature.properties['marker-size'] = 'large';\n * currentFeature.properties['marker-color'] = '#000';\n * });\n */\nfunction pointsWithinPolygon<\n G extends Polygon | MultiPolygon,\n P extends GeoJsonProperties,\n>(\n points:\n | Feature<Point | MultiPoint, P>\n | FeatureCollection<Point | MultiPoint, P>,\n polygons: Feature<G> | FeatureCollection<G> | G\n): FeatureCollection<Point | MultiPoint, P> {\n const results: Feature<Point | MultiPoint, P>[] = [];\n featureEach(points, function (point) {\n let contained = false;\n if (point.geometry.type === \"Point\") {\n geomEach(polygons, function (polygon) {\n if (pointInPolygon(point as Feature<Point, P>, polygon)) {\n contained = true;\n }\n });\n if (contained) {\n results.push(point);\n }\n } else if (point.geometry.type === \"MultiPoint\") {\n var pointsWithin: Position[] = [];\n geomEach(polygons, function (polygon) {\n coordEach(point as Feature<MultiPoint>, function (pointCoord) {\n if (pointInPolygon(pointCoord, polygon)) {\n contained = true;\n pointsWithin.push(pointCoord);\n }\n });\n });\n if (contained) {\n results.push(\n multiPoint(pointsWithin, point.properties) as Feature<MultiPoint, P>\n );\n }\n } else {\n throw new Error(\"Input geometry must be a Point or MultiPoint\");\n }\n });\n return featureCollection(results);\n}\n\nexport { pointsWithinPolygon };\nexport default pointsWithinPolygon;\n"]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { multiPoint, featureCollection } from '@turf/helpers';
|
|
3
|
-
import { featureEach, geomEach, coordEach } from '@turf/meta';
|
|
1
|
+
import { Polygon, MultiPolygon, GeoJsonProperties, Feature, Point, MultiPoint, FeatureCollection } from 'geojson';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.
|
|
@@ -37,35 +35,6 @@ import { featureEach, geomEach, coordEach } from '@turf/meta';
|
|
|
37
35
|
* currentFeature.properties['marker-color'] = '#000';
|
|
38
36
|
* });
|
|
39
37
|
*/
|
|
40
|
-
function pointsWithinPolygon(points, polygons)
|
|
41
|
-
var results = [];
|
|
42
|
-
featureEach(points, function (point) {
|
|
43
|
-
var contained = false;
|
|
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");
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return featureCollection(results);
|
|
69
|
-
}
|
|
38
|
+
declare function pointsWithinPolygon<G extends Polygon | MultiPolygon, P extends GeoJsonProperties>(points: Feature<Point | MultiPoint, P> | FeatureCollection<Point | MultiPoint, P>, polygons: Feature<G> | FeatureCollection<G> | G): FeatureCollection<Point | MultiPoint, P>;
|
|
70
39
|
|
|
71
|
-
export default pointsWithinPolygon;
|
|
40
|
+
export { pointsWithinPolygon as default, pointsWithinPolygon };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Polygon, MultiPolygon, GeoJsonProperties, Feature, Point, MultiPoint, FeatureCollection } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.
|
|
5
|
+
*
|
|
6
|
+
* @name pointsWithinPolygon
|
|
7
|
+
* @param {Feature|FeatureCollection<Point|MultiPoint>} points Point(s) or MultiPoint(s) as input search
|
|
8
|
+
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons (Multi)Polygon(s) to check if points are within
|
|
9
|
+
* @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
|
|
10
|
+
* @example
|
|
11
|
+
* var points = turf.points([
|
|
12
|
+
* [-46.6318, -23.5523],
|
|
13
|
+
* [-46.6246, -23.5325],
|
|
14
|
+
* [-46.6062, -23.5513],
|
|
15
|
+
* [-46.663, -23.554],
|
|
16
|
+
* [-46.643, -23.557]
|
|
17
|
+
* ]);
|
|
18
|
+
*
|
|
19
|
+
* var searchWithin = turf.polygon([[
|
|
20
|
+
* [-46.653,-23.543],
|
|
21
|
+
* [-46.634,-23.5346],
|
|
22
|
+
* [-46.613,-23.543],
|
|
23
|
+
* [-46.614,-23.559],
|
|
24
|
+
* [-46.631,-23.567],
|
|
25
|
+
* [-46.653,-23.560],
|
|
26
|
+
* [-46.653,-23.543]
|
|
27
|
+
* ]]);
|
|
28
|
+
*
|
|
29
|
+
* var ptsWithin = turf.pointsWithinPolygon(points, searchWithin);
|
|
30
|
+
*
|
|
31
|
+
* //addToMap
|
|
32
|
+
* var addToMap = [points, searchWithin, ptsWithin]
|
|
33
|
+
* turf.featureEach(ptsWithin, function (currentFeature) {
|
|
34
|
+
* currentFeature.properties['marker-size'] = 'large';
|
|
35
|
+
* currentFeature.properties['marker-color'] = '#000';
|
|
36
|
+
* });
|
|
37
|
+
*/
|
|
38
|
+
declare function pointsWithinPolygon<G extends Polygon | MultiPolygon, P extends GeoJsonProperties>(points: Feature<Point | MultiPoint, P> | FeatureCollection<Point | MultiPoint, P>, polygons: Feature<G> | FeatureCollection<G> | G): FeatureCollection<Point | MultiPoint, P>;
|
|
39
|
+
|
|
40
|
+
export { pointsWithinPolygon as default, pointsWithinPolygon };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { booleanPointInPolygon as pointInPolygon } from "@turf/boolean-point-in-polygon";
|
|
6
|
+
import { featureCollection, multiPoint } from "@turf/helpers";
|
|
7
|
+
import { geomEach, featureEach, coordEach } from "@turf/meta";
|
|
8
|
+
function pointsWithinPolygon(points, polygons) {
|
|
9
|
+
const results = [];
|
|
10
|
+
featureEach(points, function(point) {
|
|
11
|
+
let contained = false;
|
|
12
|
+
if (point.geometry.type === "Point") {
|
|
13
|
+
geomEach(polygons, function(polygon) {
|
|
14
|
+
if (pointInPolygon(point, polygon)) {
|
|
15
|
+
contained = true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (contained) {
|
|
19
|
+
results.push(point);
|
|
20
|
+
}
|
|
21
|
+
} else if (point.geometry.type === "MultiPoint") {
|
|
22
|
+
var pointsWithin = [];
|
|
23
|
+
geomEach(polygons, function(polygon) {
|
|
24
|
+
coordEach(point, function(pointCoord) {
|
|
25
|
+
if (pointInPolygon(pointCoord, polygon)) {
|
|
26
|
+
contained = true;
|
|
27
|
+
pointsWithin.push(pointCoord);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
if (contained) {
|
|
32
|
+
results.push(
|
|
33
|
+
multiPoint(pointsWithin, point.properties)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
throw new Error("Input geometry must be a Point or MultiPoint");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return featureCollection(results);
|
|
41
|
+
}
|
|
42
|
+
__name(pointsWithinPolygon, "pointsWithinPolygon");
|
|
43
|
+
var turf_points_within_polygon_default = pointsWithinPolygon;
|
|
44
|
+
export {
|
|
45
|
+
turf_points_within_polygon_default as default,
|
|
46
|
+
pointsWithinPolygon
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import type {\n Feature,\n FeatureCollection,\n Polygon,\n MultiPolygon,\n MultiPoint,\n Point,\n GeoJsonProperties,\n Position,\n} from \"geojson\";\nimport { booleanPointInPolygon as pointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { featureCollection, multiPoint } from \"@turf/helpers\";\nimport { geomEach, featureEach, coordEach } from \"@turf/meta\";\n\n/**\n * Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.\n *\n * @name pointsWithinPolygon\n * @param {Feature|FeatureCollection<Point|MultiPoint>} points Point(s) or MultiPoint(s) as input search\n * @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons (Multi)Polygon(s) to check if points are within\n * @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\n * @example\n * var points = turf.points([\n * [-46.6318, -23.5523],\n * [-46.6246, -23.5325],\n * [-46.6062, -23.5513],\n * [-46.663, -23.554],\n * [-46.643, -23.557]\n * ]);\n *\n * var searchWithin = turf.polygon([[\n * [-46.653,-23.543],\n * [-46.634,-23.5346],\n * [-46.613,-23.543],\n * [-46.614,-23.559],\n * [-46.631,-23.567],\n * [-46.653,-23.560],\n * [-46.653,-23.543]\n * ]]);\n *\n * var ptsWithin = turf.pointsWithinPolygon(points, searchWithin);\n *\n * //addToMap\n * var addToMap = [points, searchWithin, ptsWithin]\n * turf.featureEach(ptsWithin, function (currentFeature) {\n * currentFeature.properties['marker-size'] = 'large';\n * currentFeature.properties['marker-color'] = '#000';\n * });\n */\nfunction pointsWithinPolygon<\n G extends Polygon | MultiPolygon,\n P extends GeoJsonProperties,\n>(\n points:\n | Feature<Point | MultiPoint, P>\n | FeatureCollection<Point | MultiPoint, P>,\n polygons: Feature<G> | FeatureCollection<G> | G\n): FeatureCollection<Point | MultiPoint, P> {\n const results: Feature<Point | MultiPoint, P>[] = [];\n featureEach(points, function (point) {\n let contained = false;\n if (point.geometry.type === \"Point\") {\n geomEach(polygons, function (polygon) {\n if (pointInPolygon(point as Feature<Point, P>, polygon)) {\n contained = true;\n }\n });\n if (contained) {\n results.push(point);\n }\n } else if (point.geometry.type === \"MultiPoint\") {\n var pointsWithin: Position[] = [];\n geomEach(polygons, function (polygon) {\n coordEach(point as Feature<MultiPoint>, function (pointCoord) {\n if (pointInPolygon(pointCoord, polygon)) {\n contained = true;\n pointsWithin.push(pointCoord);\n }\n });\n });\n if (contained) {\n results.push(\n multiPoint(pointsWithin, point.properties) as Feature<MultiPoint, P>\n );\n }\n } else {\n throw new Error(\"Input geometry must be a Point or MultiPoint\");\n }\n });\n return featureCollection(results);\n}\n\nexport { pointsWithinPolygon };\nexport default pointsWithinPolygon;\n"],"mappings":";;;;AAUA,SAAS,yBAAyB,sBAAsB;AACxD,SAAS,mBAAmB,kBAAkB;AAC9C,SAAS,UAAU,aAAa,iBAAiB;AAqCjD,SAAS,oBAIP,QAGA,UAC0C;AAC1C,QAAM,UAA4C,CAAC;AACnD,cAAY,QAAQ,SAAU,OAAO;AACnC,QAAI,YAAY;AAChB,QAAI,MAAM,SAAS,SAAS,SAAS;AACnC,eAAS,UAAU,SAAU,SAAS;AACpC,YAAI,eAAe,OAA4B,OAAO,GAAG;AACvD,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,UAAI,WAAW;AACb,gBAAQ,KAAK,KAAK;AAAA,MACpB;AAAA,IACF,WAAW,MAAM,SAAS,SAAS,cAAc;AAC/C,UAAI,eAA2B,CAAC;AAChC,eAAS,UAAU,SAAU,SAAS;AACpC,kBAAU,OAA8B,SAAU,YAAY;AAC5D,cAAI,eAAe,YAAY,OAAO,GAAG;AACvC,wBAAY;AACZ,yBAAa,KAAK,UAAU;AAAA,UAC9B;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AACD,UAAI,WAAW;AACb,gBAAQ;AAAA,UACN,WAAW,cAAc,MAAM,UAAU;AAAA,QAC3C;AAAA,MACF;AAAA,IACF,OAAO;AACL,YAAM,IAAI,MAAM,8CAA8C;AAAA,IAChE;AAAA,EACF,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAzCS;AA4CT,IAAO,qCAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/points-within-polygon",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf points-within-polygon module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,41 +23,50 @@
|
|
|
23
23
|
"polygon",
|
|
24
24
|
"featurecollection"
|
|
25
25
|
],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"type": "commonjs",
|
|
27
|
+
"main": "dist/cjs/index.cjs",
|
|
28
|
+
"module": "dist/esm/index.mjs",
|
|
29
|
+
"types": "dist/cjs/index.d.ts",
|
|
28
30
|
"exports": {
|
|
29
31
|
"./package.json": "./package.json",
|
|
30
32
|
".": {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/esm/index.d.mts",
|
|
35
|
+
"default": "./dist/esm/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/index.d.ts",
|
|
39
|
+
"default": "./dist/cjs/index.cjs"
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
},
|
|
36
|
-
"types": "index.d.ts",
|
|
37
43
|
"sideEffects": false,
|
|
38
44
|
"files": [
|
|
39
|
-
"dist"
|
|
40
|
-
"index.d.ts"
|
|
45
|
+
"dist"
|
|
41
46
|
],
|
|
42
47
|
"scripts": {
|
|
43
|
-
"bench": "tsx bench.
|
|
44
|
-
"build": "
|
|
45
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
46
|
-
"test": "npm-run-all test:*",
|
|
47
|
-
"test:tape": "tsx test.
|
|
48
|
+
"bench": "tsx bench.ts",
|
|
49
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
50
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
51
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
52
|
+
"test:tape": "tsx test.ts",
|
|
48
53
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
49
54
|
},
|
|
50
55
|
"devDependencies": {
|
|
51
|
-
"benchmark": "
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
+
"@types/benchmark": "^2.1.5",
|
|
57
|
+
"@types/tape": "^4.2.32",
|
|
58
|
+
"benchmark": "^2.1.4",
|
|
59
|
+
"npm-run-all": "^4.1.5",
|
|
60
|
+
"tape": "^5.7.2",
|
|
61
|
+
"tsup": "^8.0.1",
|
|
62
|
+
"tsx": "^4.6.2",
|
|
63
|
+
"typescript": "^5.2.2"
|
|
56
64
|
},
|
|
57
65
|
"dependencies": {
|
|
58
|
-
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.
|
|
59
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
60
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
66
|
+
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.110+1411d63a7",
|
|
67
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
68
|
+
"@turf/meta": "^7.0.0-alpha.110+1411d63a7",
|
|
69
|
+
"tslib": "^2.6.2"
|
|
61
70
|
},
|
|
62
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
63
72
|
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var pointInPolygon = require('@turf/boolean-point-in-polygon');
|
|
4
|
-
var helpers = require('@turf/helpers');
|
|
5
|
-
var meta = require('@turf/meta');
|
|
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
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.
|
|
13
|
-
*
|
|
14
|
-
* @name pointsWithinPolygon
|
|
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
|
|
18
|
-
* @example
|
|
19
|
-
* var points = turf.points([
|
|
20
|
-
* [-46.6318, -23.5523],
|
|
21
|
-
* [-46.6246, -23.5325],
|
|
22
|
-
* [-46.6062, -23.5513],
|
|
23
|
-
* [-46.663, -23.554],
|
|
24
|
-
* [-46.643, -23.557]
|
|
25
|
-
* ]);
|
|
26
|
-
*
|
|
27
|
-
* var searchWithin = turf.polygon([[
|
|
28
|
-
* [-46.653,-23.543],
|
|
29
|
-
* [-46.634,-23.5346],
|
|
30
|
-
* [-46.613,-23.543],
|
|
31
|
-
* [-46.614,-23.559],
|
|
32
|
-
* [-46.631,-23.567],
|
|
33
|
-
* [-46.653,-23.560],
|
|
34
|
-
* [-46.653,-23.543]
|
|
35
|
-
* ]]);
|
|
36
|
-
*
|
|
37
|
-
* var ptsWithin = turf.pointsWithinPolygon(points, searchWithin);
|
|
38
|
-
*
|
|
39
|
-
* //addToMap
|
|
40
|
-
* var addToMap = [points, searchWithin, ptsWithin]
|
|
41
|
-
* turf.featureEach(ptsWithin, function (currentFeature) {
|
|
42
|
-
* currentFeature.properties['marker-size'] = 'large';
|
|
43
|
-
* currentFeature.properties['marker-color'] = '#000';
|
|
44
|
-
* });
|
|
45
|
-
*/
|
|
46
|
-
function pointsWithinPolygon(points, polygons) {
|
|
47
|
-
var results = [];
|
|
48
|
-
meta.featureEach(points, function (point) {
|
|
49
|
-
var contained = false;
|
|
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");
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return helpers.featureCollection(results);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = pointsWithinPolygon;
|
|
78
|
-
module.exports.default = pointsWithinPolygon;
|
package/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Feature,
|
|
3
|
-
FeatureCollection,
|
|
4
|
-
Polygon,
|
|
5
|
-
MultiPolygon,
|
|
6
|
-
MultiPoint,
|
|
7
|
-
Point,
|
|
8
|
-
GeoJsonProperties,
|
|
9
|
-
} from "geojson";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* http://turfjs.org/docs/#pointswithinpolygon
|
|
13
|
-
*/
|
|
14
|
-
export default function pointsWithinPolygon<
|
|
15
|
-
F extends Point | MultiPoint,
|
|
16
|
-
G extends Polygon | MultiPolygon,
|
|
17
|
-
P = GeoJsonProperties
|
|
18
|
-
>(
|
|
19
|
-
points: Feature<F, P> | FeatureCollection<F, P>,
|
|
20
|
-
polygons: Feature<G> | FeatureCollection<G> | G
|
|
21
|
-
): FeatureCollection<F, P>;
|