@turf/boolean-point-in-polygon 7.0.0-alpha.0 → 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 +45 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +6 -3
- package/dist/esm/index.d.mts +32 -0
- package/dist/esm/index.mjs +45 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +30 -24
- package/dist/es/index.js +0 -70
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -74
package/README.md
CHANGED
|
@@ -52,26 +52,21 @@ Returns **[boolean][9]** `true` if the Point is inside the Polygon; `false` if t
|
|
|
52
52
|
|
|
53
53
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
54
54
|
|
|
55
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
56
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
57
|
-
./scripts/generate-readmes in the turf project. -->
|
|
55
|
+
<!-- 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. -->
|
|
58
56
|
|
|
59
57
|
---
|
|
60
58
|
|
|
61
|
-
This module is part of the [Turfjs project](
|
|
62
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
63
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
64
|
-
PRs and issues.
|
|
59
|
+
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.
|
|
65
60
|
|
|
66
61
|
### Installation
|
|
67
62
|
|
|
68
|
-
Install this module individually:
|
|
63
|
+
Install this single module individually:
|
|
69
64
|
|
|
70
65
|
```sh
|
|
71
66
|
$ npm install @turf/boolean-point-in-polygon
|
|
72
67
|
```
|
|
73
68
|
|
|
74
|
-
Or install the
|
|
69
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
75
70
|
|
|
76
71
|
```sh
|
|
77
72
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _pointinpolygonhao = require('point-in-polygon-hao'); var _pointinpolygonhao2 = _interopRequireDefault(_pointinpolygonhao);
|
|
6
|
+
var _invariant = require('@turf/invariant');
|
|
7
|
+
function booleanPointInPolygon(point, polygon, options = {}) {
|
|
8
|
+
if (!point) {
|
|
9
|
+
throw new Error("point is required");
|
|
10
|
+
}
|
|
11
|
+
if (!polygon) {
|
|
12
|
+
throw new Error("polygon is required");
|
|
13
|
+
}
|
|
14
|
+
const pt = _invariant.getCoord.call(void 0, point);
|
|
15
|
+
const geom = _invariant.getGeom.call(void 0, polygon);
|
|
16
|
+
const type = geom.type;
|
|
17
|
+
const bbox = polygon.bbox;
|
|
18
|
+
let polys = geom.coordinates;
|
|
19
|
+
if (bbox && inBBox(pt, bbox) === false) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (type === "Polygon") {
|
|
23
|
+
polys = [polys];
|
|
24
|
+
}
|
|
25
|
+
let result = false;
|
|
26
|
+
for (var i = 0; i < polys.length; ++i) {
|
|
27
|
+
const polyResult = _pointinpolygonhao2.default.call(void 0, pt, polys[i]);
|
|
28
|
+
if (polyResult === 0)
|
|
29
|
+
return options.ignoreBoundary ? false : true;
|
|
30
|
+
else if (polyResult)
|
|
31
|
+
result = true;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
__name(booleanPointInPolygon, "booleanPointInPolygon");
|
|
36
|
+
function inBBox(pt, bbox) {
|
|
37
|
+
return bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1];
|
|
38
|
+
}
|
|
39
|
+
__name(inBBox, "inBBox");
|
|
40
|
+
var turf_boolean_point_in_polygon_default = booleanPointInPolygon;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.booleanPointInPolygon = booleanPointInPolygon; exports.default = turf_boolean_point_in_polygon_default;
|
|
45
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAAA,OAAO,SAAS;AAShB,SAAS,UAAU,eAAe;AA6BlC,SAAS,sBAIP,OACA,SACA,UAEI,CAAC,GACL;AAEA,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,QAAM,KAAK,SAAS,KAAK;AACzB,QAAM,OAAO,QAAQ,OAAO;AAC5B,QAAM,OAAO,KAAK;AAClB,QAAM,OAAO,QAAQ;AACrB,MAAI,QAAe,KAAK;AAGxB,MAAI,QAAQ,OAAO,IAAI,IAAI,MAAM,OAAO;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,WAAW;AACtB,YAAQ,CAAC,KAAK;AAAA,EAChB;AACA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,EAAE,GAAG;AACrC,UAAM,aAAa,IAAI,IAAI,MAAM,CAAC,CAAC;AACnC,QAAI,eAAe;AAAG,aAAO,QAAQ,iBAAiB,QAAQ;AAAA,aACrD;AAAY,eAAS;AAAA,EAChC;AAEA,SAAO;AACT;AAxCS;AAkDT,SAAS,OAAO,IAAc,MAAY;AACxC,SACE,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC;AAE/E;AAJS;AAOT,IAAO,wCAAQ","sourcesContent":["import pip from \"point-in-polygon-hao\";\nimport {\n BBox,\n Feature,\n MultiPolygon,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport { Coord } from \"@turf/helpers\";\nimport { getCoord, getGeom } from \"@turf/invariant\";\n\n// http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule\n// modified from: https://github.com/substack/point-in-polygon/blob/master/index.js\n// which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html\n/**\n * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point\n * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.\n *\n * @name booleanPointInPolygon\n * @param {Coord} point input point\n * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if\n * the point is inside the polygon otherwise false.\n * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon\n * @example\n * var pt = turf.point([-77, 44]);\n * var poly = turf.polygon([[\n * [-81, 41],\n * [-81, 47],\n * [-72, 47],\n * [-72, 41],\n * [-81, 41]\n * ]]);\n *\n * turf.booleanPointInPolygon(pt, poly);\n * //= true\n */\nfunction booleanPointInPolygon<\n G extends Polygon | MultiPolygon,\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n point: Coord,\n polygon: Feature<G, P> | G,\n options: {\n ignoreBoundary?: boolean;\n } = {}\n) {\n // validation\n if (!point) {\n throw new Error(\"point is required\");\n }\n if (!polygon) {\n throw new Error(\"polygon is required\");\n }\n\n const pt = getCoord(point);\n const geom = getGeom(polygon);\n const type = geom.type;\n const bbox = polygon.bbox;\n let polys: any[] = geom.coordinates;\n\n // Quick elimination if point is not inside bbox\n if (bbox && inBBox(pt, bbox) === false) {\n return false;\n }\n\n if (type === \"Polygon\") {\n polys = [polys];\n }\n let result = false;\n for (var i = 0; i < polys.length; ++i) {\n const polyResult = pip(pt, polys[i]);\n if (polyResult === 0) return options.ignoreBoundary ? false : true;\n else if (polyResult) result = true;\n }\n\n return result;\n}\n\n/**\n * inBBox\n *\n * @private\n * @param {Position} pt point [x,y]\n * @param {BBox} bbox BBox [west, south, east, north]\n * @returns {boolean} true/false if point is inside BBox\n */\nfunction inBBox(pt: number[], bbox: BBox) {\n return (\n bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]\n );\n}\n\nexport { booleanPointInPolygon };\nexport default booleanPointInPolygon;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Coord } from
|
|
1
|
+
import { Polygon, MultiPolygon, GeoJsonProperties, Feature } from 'geojson';
|
|
2
|
+
import { Coord } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
|
|
5
6
|
* resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
|
|
@@ -24,6 +25,8 @@ import { Coord } from "@turf/helpers";
|
|
|
24
25
|
* turf.booleanPointInPolygon(pt, poly);
|
|
25
26
|
* //= true
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
declare function booleanPointInPolygon<G extends Polygon | MultiPolygon, P extends GeoJsonProperties = GeoJsonProperties>(point: Coord, polygon: Feature<G, P> | G, options?: {
|
|
28
29
|
ignoreBoundary?: boolean;
|
|
29
30
|
}): boolean;
|
|
31
|
+
|
|
32
|
+
export { booleanPointInPolygon, booleanPointInPolygon as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Polygon, MultiPolygon, GeoJsonProperties, Feature } from 'geojson';
|
|
2
|
+
import { Coord } from '@turf/helpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
|
|
6
|
+
* resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
|
|
7
|
+
*
|
|
8
|
+
* @name booleanPointInPolygon
|
|
9
|
+
* @param {Coord} point input point
|
|
10
|
+
* @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon
|
|
11
|
+
* @param {Object} [options={}] Optional parameters
|
|
12
|
+
* @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if
|
|
13
|
+
* the point is inside the polygon otherwise false.
|
|
14
|
+
* @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon
|
|
15
|
+
* @example
|
|
16
|
+
* var pt = turf.point([-77, 44]);
|
|
17
|
+
* var poly = turf.polygon([[
|
|
18
|
+
* [-81, 41],
|
|
19
|
+
* [-81, 47],
|
|
20
|
+
* [-72, 47],
|
|
21
|
+
* [-72, 41],
|
|
22
|
+
* [-81, 41]
|
|
23
|
+
* ]]);
|
|
24
|
+
*
|
|
25
|
+
* turf.booleanPointInPolygon(pt, poly);
|
|
26
|
+
* //= true
|
|
27
|
+
*/
|
|
28
|
+
declare function booleanPointInPolygon<G extends Polygon | MultiPolygon, P extends GeoJsonProperties = GeoJsonProperties>(point: Coord, polygon: Feature<G, P> | G, options?: {
|
|
29
|
+
ignoreBoundary?: boolean;
|
|
30
|
+
}): boolean;
|
|
31
|
+
|
|
32
|
+
export { booleanPointInPolygon, booleanPointInPolygon as default };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import pip from "point-in-polygon-hao";
|
|
6
|
+
import { getCoord, getGeom } from "@turf/invariant";
|
|
7
|
+
function booleanPointInPolygon(point, polygon, options = {}) {
|
|
8
|
+
if (!point) {
|
|
9
|
+
throw new Error("point is required");
|
|
10
|
+
}
|
|
11
|
+
if (!polygon) {
|
|
12
|
+
throw new Error("polygon is required");
|
|
13
|
+
}
|
|
14
|
+
const pt = getCoord(point);
|
|
15
|
+
const geom = getGeom(polygon);
|
|
16
|
+
const type = geom.type;
|
|
17
|
+
const bbox = polygon.bbox;
|
|
18
|
+
let polys = geom.coordinates;
|
|
19
|
+
if (bbox && inBBox(pt, bbox) === false) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (type === "Polygon") {
|
|
23
|
+
polys = [polys];
|
|
24
|
+
}
|
|
25
|
+
let result = false;
|
|
26
|
+
for (var i = 0; i < polys.length; ++i) {
|
|
27
|
+
const polyResult = pip(pt, polys[i]);
|
|
28
|
+
if (polyResult === 0)
|
|
29
|
+
return options.ignoreBoundary ? false : true;
|
|
30
|
+
else if (polyResult)
|
|
31
|
+
result = true;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
__name(booleanPointInPolygon, "booleanPointInPolygon");
|
|
36
|
+
function inBBox(pt, bbox) {
|
|
37
|
+
return bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1];
|
|
38
|
+
}
|
|
39
|
+
__name(inBBox, "inBBox");
|
|
40
|
+
var turf_boolean_point_in_polygon_default = booleanPointInPolygon;
|
|
41
|
+
export {
|
|
42
|
+
booleanPointInPolygon,
|
|
43
|
+
turf_boolean_point_in_polygon_default as default
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import pip from \"point-in-polygon-hao\";\nimport {\n BBox,\n Feature,\n MultiPolygon,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport { Coord } from \"@turf/helpers\";\nimport { getCoord, getGeom } from \"@turf/invariant\";\n\n// http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule\n// modified from: https://github.com/substack/point-in-polygon/blob/master/index.js\n// which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html\n/**\n * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point\n * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.\n *\n * @name booleanPointInPolygon\n * @param {Coord} point input point\n * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if\n * the point is inside the polygon otherwise false.\n * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon\n * @example\n * var pt = turf.point([-77, 44]);\n * var poly = turf.polygon([[\n * [-81, 41],\n * [-81, 47],\n * [-72, 47],\n * [-72, 41],\n * [-81, 41]\n * ]]);\n *\n * turf.booleanPointInPolygon(pt, poly);\n * //= true\n */\nfunction booleanPointInPolygon<\n G extends Polygon | MultiPolygon,\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n point: Coord,\n polygon: Feature<G, P> | G,\n options: {\n ignoreBoundary?: boolean;\n } = {}\n) {\n // validation\n if (!point) {\n throw new Error(\"point is required\");\n }\n if (!polygon) {\n throw new Error(\"polygon is required\");\n }\n\n const pt = getCoord(point);\n const geom = getGeom(polygon);\n const type = geom.type;\n const bbox = polygon.bbox;\n let polys: any[] = geom.coordinates;\n\n // Quick elimination if point is not inside bbox\n if (bbox && inBBox(pt, bbox) === false) {\n return false;\n }\n\n if (type === \"Polygon\") {\n polys = [polys];\n }\n let result = false;\n for (var i = 0; i < polys.length; ++i) {\n const polyResult = pip(pt, polys[i]);\n if (polyResult === 0) return options.ignoreBoundary ? false : true;\n else if (polyResult) result = true;\n }\n\n return result;\n}\n\n/**\n * inBBox\n *\n * @private\n * @param {Position} pt point [x,y]\n * @param {BBox} bbox BBox [west, south, east, north]\n * @returns {boolean} true/false if point is inside BBox\n */\nfunction inBBox(pt: number[], bbox: BBox) {\n return (\n bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]\n );\n}\n\nexport { booleanPointInPolygon };\nexport default booleanPointInPolygon;\n"],"mappings":";;;;AAAA,OAAO,SAAS;AAShB,SAAS,UAAU,eAAe;AA6BlC,SAAS,sBAIP,OACA,SACA,UAEI,CAAC,GACL;AAEA,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,QAAM,KAAK,SAAS,KAAK;AACzB,QAAM,OAAO,QAAQ,OAAO;AAC5B,QAAM,OAAO,KAAK;AAClB,QAAM,OAAO,QAAQ;AACrB,MAAI,QAAe,KAAK;AAGxB,MAAI,QAAQ,OAAO,IAAI,IAAI,MAAM,OAAO;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,WAAW;AACtB,YAAQ,CAAC,KAAK;AAAA,EAChB;AACA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,EAAE,GAAG;AACrC,UAAM,aAAa,IAAI,IAAI,MAAM,CAAC,CAAC;AACnC,QAAI,eAAe;AAAG,aAAO,QAAQ,iBAAiB,QAAQ;AAAA,aACrD;AAAY,eAAS;AAAA,EAChC;AAEA,SAAO;AACT;AAxCS;AAkDT,SAAS,OAAO,IAAc,MAAY;AACxC,SACE,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC;AAE/E;AAJS;AAOT,IAAO,wCAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/boolean-point-in-polygon",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf boolean-point-in-polygon module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,43 +24,49 @@
|
|
|
24
24
|
"bin",
|
|
25
25
|
"gis"
|
|
26
26
|
],
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"type": "commonjs",
|
|
28
|
+
"main": "dist/cjs/index.cjs",
|
|
29
|
+
"module": "dist/esm/index.mjs",
|
|
30
|
+
"types": "dist/cjs/index.d.ts",
|
|
29
31
|
"exports": {
|
|
30
32
|
"./package.json": "./package.json",
|
|
31
33
|
".": {
|
|
32
|
-
"import":
|
|
33
|
-
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/esm/index.d.mts",
|
|
36
|
+
"default": "./dist/esm/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/cjs/index.d.ts",
|
|
40
|
+
"default": "./dist/cjs/index.cjs"
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
43
|
},
|
|
36
|
-
"types": "dist/js/index.d.ts",
|
|
37
44
|
"sideEffects": false,
|
|
38
45
|
"files": [
|
|
39
46
|
"dist"
|
|
40
47
|
],
|
|
41
48
|
"scripts": {
|
|
42
|
-
"bench": "
|
|
43
|
-
"build": "
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"test": "npm-run-all test:*",
|
|
48
|
-
"test:tape": "ts-node -r esm test.js"
|
|
49
|
+
"bench": "tsx bench.ts",
|
|
50
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
51
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
52
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
53
|
+
"test:tape": "tsx test.ts"
|
|
49
54
|
},
|
|
50
55
|
"devDependencies": {
|
|
51
|
-
"@types/
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
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"
|
|
58
64
|
},
|
|
59
65
|
"dependencies": {
|
|
60
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
61
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
66
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
67
|
+
"@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
|
|
62
68
|
"point-in-polygon-hao": "^1.1.0",
|
|
63
|
-
"tslib": "^2.
|
|
69
|
+
"tslib": "^2.6.2"
|
|
64
70
|
},
|
|
65
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
66
72
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import pip from "point-in-polygon-hao";
|
|
2
|
-
import { getCoord, getGeom } from "@turf/invariant";
|
|
3
|
-
// http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
|
|
4
|
-
// modified from: https://github.com/substack/point-in-polygon/blob/master/index.js
|
|
5
|
-
// which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
6
|
-
/**
|
|
7
|
-
* Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
|
|
8
|
-
* resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
|
|
9
|
-
*
|
|
10
|
-
* @name booleanPointInPolygon
|
|
11
|
-
* @param {Coord} point input point
|
|
12
|
-
* @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon
|
|
13
|
-
* @param {Object} [options={}] Optional parameters
|
|
14
|
-
* @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if
|
|
15
|
-
* the point is inside the polygon otherwise false.
|
|
16
|
-
* @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon
|
|
17
|
-
* @example
|
|
18
|
-
* var pt = turf.point([-77, 44]);
|
|
19
|
-
* var poly = turf.polygon([[
|
|
20
|
-
* [-81, 41],
|
|
21
|
-
* [-81, 47],
|
|
22
|
-
* [-72, 47],
|
|
23
|
-
* [-72, 41],
|
|
24
|
-
* [-81, 41]
|
|
25
|
-
* ]]);
|
|
26
|
-
*
|
|
27
|
-
* turf.booleanPointInPolygon(pt, poly);
|
|
28
|
-
* //= true
|
|
29
|
-
*/
|
|
30
|
-
export default function booleanPointInPolygon(point, polygon, options = {}) {
|
|
31
|
-
// validation
|
|
32
|
-
if (!point) {
|
|
33
|
-
throw new Error("point is required");
|
|
34
|
-
}
|
|
35
|
-
if (!polygon) {
|
|
36
|
-
throw new Error("polygon is required");
|
|
37
|
-
}
|
|
38
|
-
const pt = getCoord(point);
|
|
39
|
-
const geom = getGeom(polygon);
|
|
40
|
-
const type = geom.type;
|
|
41
|
-
const bbox = polygon.bbox;
|
|
42
|
-
let polys = geom.coordinates;
|
|
43
|
-
// Quick elimination if point is not inside bbox
|
|
44
|
-
if (bbox && inBBox(pt, bbox) === false) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
if (type === "Polygon") {
|
|
48
|
-
polys = [polys];
|
|
49
|
-
}
|
|
50
|
-
let result = false;
|
|
51
|
-
for (var i = 0; i < polys.length; ++i) {
|
|
52
|
-
const polyResult = pip(pt, polys[i]);
|
|
53
|
-
if (polyResult === 0)
|
|
54
|
-
return options.ignoreBoundary ? false : true;
|
|
55
|
-
else if (polyResult)
|
|
56
|
-
result = true;
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* inBBox
|
|
62
|
-
*
|
|
63
|
-
* @private
|
|
64
|
-
* @param {Position} pt point [x,y]
|
|
65
|
-
* @param {BBox} bbox BBox [west, south, east, north]
|
|
66
|
-
* @returns {boolean} true/false if point is inside BBox
|
|
67
|
-
*/
|
|
68
|
-
function inBBox(pt, bbox) {
|
|
69
|
-
return (bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]);
|
|
70
|
-
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const point_in_polygon_hao_1 = tslib_1.__importDefault(require("point-in-polygon-hao"));
|
|
5
|
-
const invariant_1 = require("@turf/invariant");
|
|
6
|
-
// http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
|
|
7
|
-
// modified from: https://github.com/substack/point-in-polygon/blob/master/index.js
|
|
8
|
-
// which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
9
|
-
/**
|
|
10
|
-
* Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
|
|
11
|
-
* resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
|
|
12
|
-
*
|
|
13
|
-
* @name booleanPointInPolygon
|
|
14
|
-
* @param {Coord} point input point
|
|
15
|
-
* @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon
|
|
16
|
-
* @param {Object} [options={}] Optional parameters
|
|
17
|
-
* @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if
|
|
18
|
-
* the point is inside the polygon otherwise false.
|
|
19
|
-
* @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon
|
|
20
|
-
* @example
|
|
21
|
-
* var pt = turf.point([-77, 44]);
|
|
22
|
-
* var poly = turf.polygon([[
|
|
23
|
-
* [-81, 41],
|
|
24
|
-
* [-81, 47],
|
|
25
|
-
* [-72, 47],
|
|
26
|
-
* [-72, 41],
|
|
27
|
-
* [-81, 41]
|
|
28
|
-
* ]]);
|
|
29
|
-
*
|
|
30
|
-
* turf.booleanPointInPolygon(pt, poly);
|
|
31
|
-
* //= true
|
|
32
|
-
*/
|
|
33
|
-
function booleanPointInPolygon(point, polygon, options = {}) {
|
|
34
|
-
// validation
|
|
35
|
-
if (!point) {
|
|
36
|
-
throw new Error("point is required");
|
|
37
|
-
}
|
|
38
|
-
if (!polygon) {
|
|
39
|
-
throw new Error("polygon is required");
|
|
40
|
-
}
|
|
41
|
-
const pt = invariant_1.getCoord(point);
|
|
42
|
-
const geom = invariant_1.getGeom(polygon);
|
|
43
|
-
const type = geom.type;
|
|
44
|
-
const bbox = polygon.bbox;
|
|
45
|
-
let polys = geom.coordinates;
|
|
46
|
-
// Quick elimination if point is not inside bbox
|
|
47
|
-
if (bbox && inBBox(pt, bbox) === false) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
if (type === "Polygon") {
|
|
51
|
-
polys = [polys];
|
|
52
|
-
}
|
|
53
|
-
let result = false;
|
|
54
|
-
for (var i = 0; i < polys.length; ++i) {
|
|
55
|
-
const polyResult = point_in_polygon_hao_1.default(pt, polys[i]);
|
|
56
|
-
if (polyResult === 0)
|
|
57
|
-
return options.ignoreBoundary ? false : true;
|
|
58
|
-
else if (polyResult)
|
|
59
|
-
result = true;
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
exports.default = booleanPointInPolygon;
|
|
64
|
-
/**
|
|
65
|
-
* inBBox
|
|
66
|
-
*
|
|
67
|
-
* @private
|
|
68
|
-
* @param {Position} pt point [x,y]
|
|
69
|
-
* @param {BBox} bbox BBox [west, south, east, north]
|
|
70
|
-
* @returns {boolean} true/false if point is inside BBox
|
|
71
|
-
*/
|
|
72
|
-
function inBBox(pt, bbox) {
|
|
73
|
-
return (bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]);
|
|
74
|
-
}
|