@turf/interpolate 7.0.0-alpha.1 → 7.0.0-alpha.111

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 CHANGED
@@ -49,26 +49,21 @@ Returns **[FeatureCollection][2]<([Point][3] | [Polygon][7])>** grid of points o
49
49
 
50
50
  [7]: https://tools.ietf.org/html/rfc7946#section-3.1.6
51
51
 
52
- <!-- This file is automatically generated. Please don't edit it directly:
53
- if you find an error, edit the source file (likely index.js), and re-run
54
- ./scripts/generate-readmes in the turf project. -->
52
+ <!-- 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. -->
55
53
 
56
54
  ---
57
55
 
58
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
59
- module collection dedicated to geographic algorithms. It is maintained in the
60
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
61
- PRs and issues.
56
+ 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.
62
57
 
63
58
  ### Installation
64
59
 
65
- Install this module individually:
60
+ Install this single module individually:
66
61
 
67
62
  ```sh
68
63
  $ npm install @turf/interpolate
69
64
  ```
70
65
 
71
- Or install the Turf module that includes it as a function:
66
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
72
67
 
73
68
  ```sh
74
69
  $ npm install @turf/turf
@@ -0,0 +1,87 @@
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.js
5
+ var _bbox = require('@turf/bbox');
6
+ var _hexgrid = require('@turf/hex-grid');
7
+ var _pointgrid = require('@turf/point-grid');
8
+ var _distance = require('@turf/distance');
9
+ var _centroid = require('@turf/centroid');
10
+ var _squaregrid = require('@turf/square-grid');
11
+ var _trianglegrid = require('@turf/triangle-grid');
12
+ var _clone = require('@turf/clone');
13
+ var _helpers = require('@turf/helpers');
14
+ var _meta = require('@turf/meta');
15
+ var _invariant = require('@turf/invariant');
16
+ function interpolate(points, cellSize, options) {
17
+ options = options || {};
18
+ if (typeof options !== "object")
19
+ throw new Error("options is invalid");
20
+ var gridType = options.gridType;
21
+ var property = options.property;
22
+ var weight = options.weight;
23
+ if (!points)
24
+ throw new Error("points is required");
25
+ _invariant.collectionOf.call(void 0, points, "Point", "input must contain Points");
26
+ if (!cellSize)
27
+ throw new Error("cellSize is required");
28
+ if (weight !== void 0 && typeof weight !== "number")
29
+ throw new Error("weight must be a number");
30
+ property = property || "elevation";
31
+ gridType = gridType || "square";
32
+ weight = weight || 1;
33
+ var box = _bbox.bbox.call(void 0, points);
34
+ var grid;
35
+ switch (gridType) {
36
+ case "point":
37
+ case "points":
38
+ grid = _pointgrid.pointGrid.call(void 0, box, cellSize, options);
39
+ break;
40
+ case "square":
41
+ case "squares":
42
+ grid = _squaregrid.squareGrid.call(void 0, box, cellSize, options);
43
+ break;
44
+ case "hex":
45
+ case "hexes":
46
+ grid = _hexgrid.hexGrid.call(void 0, box, cellSize, options);
47
+ break;
48
+ case "triangle":
49
+ case "triangles":
50
+ grid = _trianglegrid.triangleGrid.call(void 0, box, cellSize, options);
51
+ break;
52
+ default:
53
+ throw new Error("invalid gridType");
54
+ }
55
+ var results = [];
56
+ _meta.featureEach.call(void 0, grid, function(gridFeature) {
57
+ var zw = 0;
58
+ var sw = 0;
59
+ _meta.featureEach.call(void 0, points, function(point) {
60
+ var gridPoint = gridType === "point" ? gridFeature : _centroid.centroid.call(void 0, gridFeature);
61
+ var d = _distance.distance.call(void 0, gridPoint, point, options);
62
+ var zValue;
63
+ if (property !== void 0)
64
+ zValue = point.properties[property];
65
+ if (zValue === void 0)
66
+ zValue = point.geometry.coordinates[2];
67
+ if (zValue === void 0)
68
+ throw new Error("zValue is missing");
69
+ if (d === 0)
70
+ zw = zValue;
71
+ var w = 1 / Math.pow(d, weight);
72
+ sw += w;
73
+ zw += w * zValue;
74
+ });
75
+ var newFeature = _clone.clone.call(void 0, gridFeature);
76
+ newFeature.properties[property] = zw / sw;
77
+ results.push(newFeature);
78
+ });
79
+ return _helpers.featureCollection.call(void 0, results);
80
+ }
81
+ __name(interpolate, "interpolate");
82
+ var turf_interpolate_default = interpolate;
83
+
84
+
85
+
86
+ exports.default = turf_interpolate_default; exports.interpolate = interpolate;
87
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.js"],"names":[],"mappings":";;;;AAAA,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AACtB,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AA2B7B,SAAS,YAAY,QAAQ,UAAU,SAAS;AAE9C,YAAU,WAAW,CAAC;AACtB,MAAI,OAAO,YAAY;AAAU,UAAM,IAAI,MAAM,oBAAoB;AACrE,MAAI,WAAW,QAAQ;AACvB,MAAI,WAAW,QAAQ;AACvB,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAQ,UAAM,IAAI,MAAM,oBAAoB;AACjD,eAAa,QAAQ,SAAS,2BAA2B;AACzD,MAAI,CAAC;AAAU,UAAM,IAAI,MAAM,sBAAsB;AACrD,MAAI,WAAW,UAAa,OAAO,WAAW;AAC5C,UAAM,IAAI,MAAM,yBAAyB;AAG3C,aAAW,YAAY;AACvB,aAAW,YAAY;AACvB,WAAS,UAAU;AAEnB,MAAI,MAAM,KAAK,MAAM;AACrB,MAAI;AACJ,UAAQ,UAAU;AAAA,IAChB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,UAAU,KAAK,UAAU,OAAO;AACvC;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,aAAO,WAAW,KAAK,UAAU,OAAO;AACxC;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,aAAO,QAAQ,KAAK,UAAU,OAAO;AACrC;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,aAAO,aAAa,KAAK,UAAU,OAAO;AAC1C;AAAA,IACF;AACE,YAAM,IAAI,MAAM,kBAAkB;AAAA,EACtC;AACA,MAAI,UAAU,CAAC;AACf,cAAY,MAAM,SAAU,aAAa;AACvC,QAAI,KAAK;AACT,QAAI,KAAK;AAET,gBAAY,QAAQ,SAAU,OAAO;AACnC,UAAI,YACF,aAAa,UAAU,cAAc,SAAS,WAAW;AAC3D,UAAI,IAAI,SAAS,WAAW,OAAO,OAAO;AAC1C,UAAI;AAEJ,UAAI,aAAa;AAAW,iBAAS,MAAM,WAAW,QAAQ;AAC9D,UAAI,WAAW;AAAW,iBAAS,MAAM,SAAS,YAAY,CAAC;AAC/D,UAAI,WAAW;AAAW,cAAM,IAAI,MAAM,mBAAmB;AAC7D,UAAI,MAAM;AAAG,aAAK;AAClB,UAAI,IAAI,IAAM,KAAK,IAAI,GAAG,MAAM;AAChC,YAAM;AACN,YAAM,IAAI;AAAA,IACZ,CAAC;AAED,QAAI,aAAa,MAAM,WAAW;AAClC,eAAW,WAAW,QAAQ,IAAI,KAAK;AACvC,YAAQ,KAAK,UAAU;AAAA,EACzB,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAnES;AAsET,IAAO,2BAAQ","sourcesContent":["import { bbox } from \"@turf/bbox\";\nimport { hexGrid } from \"@turf/hex-grid\";\nimport { pointGrid } from \"@turf/point-grid\";\nimport { distance } from \"@turf/distance\";\nimport { centroid } from \"@turf/centroid\";\nimport { squareGrid } from \"@turf/square-grid\";\nimport { triangleGrid } from \"@turf/triangle-grid\";\nimport { clone } from \"@turf/clone\";\nimport { featureCollection } from \"@turf/helpers\";\nimport { featureEach } from \"@turf/meta\";\nimport { collectionOf } from \"@turf/invariant\";\n\n/**\n * Takes a set of points and estimates their 'property' values on a grid using the [Inverse Distance Weighting (IDW) method](https://en.wikipedia.org/wiki/Inverse_distance_weighting).\n *\n * @name interpolate\n * @param {FeatureCollection<Point>} points with known value\n * @param {number} cellSize the distance across each grid point\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.gridType='square'] defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle')\n * @param {string} [options.property='elevation'] the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists.\n * @param {string} [options.units='kilometers'] used in calculating cellSize, can be degrees, radians, miles, or kilometers\n * @param {number} [options.weight=1] exponent regulating the distance-decay weighting\n * @returns {FeatureCollection<Point|Polygon>} grid of points or polygons with interpolated 'property'\n * @example\n * var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]});\n *\n * // add a random property to each point\n * turf.featureEach(points, function(point) {\n * point.properties.solRad = Math.random() * 50;\n * });\n * var options = {gridType: 'points', property: 'solRad', units: 'miles'};\n * var grid = turf.interpolate(points, 100, options);\n *\n * //addToMap\n * var addToMap = [grid];\n */\nfunction interpolate(points, cellSize, options) {\n // Optional parameters\n options = options || {};\n if (typeof options !== \"object\") throw new Error(\"options is invalid\");\n var gridType = options.gridType;\n var property = options.property;\n var weight = options.weight;\n\n // validation\n if (!points) throw new Error(\"points is required\");\n collectionOf(points, \"Point\", \"input must contain Points\");\n if (!cellSize) throw new Error(\"cellSize is required\");\n if (weight !== undefined && typeof weight !== \"number\")\n throw new Error(\"weight must be a number\");\n\n // default values\n property = property || \"elevation\";\n gridType = gridType || \"square\";\n weight = weight || 1;\n\n var box = bbox(points);\n var grid;\n switch (gridType) {\n case \"point\":\n case \"points\":\n grid = pointGrid(box, cellSize, options);\n break;\n case \"square\":\n case \"squares\":\n grid = squareGrid(box, cellSize, options);\n break;\n case \"hex\":\n case \"hexes\":\n grid = hexGrid(box, cellSize, options);\n break;\n case \"triangle\":\n case \"triangles\":\n grid = triangleGrid(box, cellSize, options);\n break;\n default:\n throw new Error(\"invalid gridType\");\n }\n var results = [];\n featureEach(grid, function (gridFeature) {\n var zw = 0;\n var sw = 0;\n // calculate the distance from each input point to the grid points\n featureEach(points, function (point) {\n var gridPoint =\n gridType === \"point\" ? gridFeature : centroid(gridFeature);\n var d = distance(gridPoint, point, options);\n var zValue;\n // property has priority for zValue, fallbacks to 3rd coordinate from geometry\n if (property !== undefined) zValue = point.properties[property];\n if (zValue === undefined) zValue = point.geometry.coordinates[2];\n if (zValue === undefined) throw new Error(\"zValue is missing\");\n if (d === 0) zw = zValue;\n var w = 1.0 / Math.pow(d, weight);\n sw += w;\n zw += w * zValue;\n });\n // write interpolated value for each grid point\n var newFeature = clone(gridFeature);\n newFeature.properties[property] = zw / sw;\n results.push(newFeature);\n });\n return featureCollection(results);\n}\n\nexport { interpolate };\nexport default interpolate;\n"]}
@@ -0,0 +1,28 @@
1
+ import { FeatureCollection, Point, Polygon } from 'geojson';
2
+ import { Units, Grid } from '@turf/helpers';
3
+
4
+ /**
5
+ * http://turfjs.org/docs/#interpolate
6
+ */
7
+ declare function interpolate(
8
+ points: FeatureCollection<Point>,
9
+ cellSize: number,
10
+ options?: {
11
+ gridType?: "point";
12
+ property?: string;
13
+ units?: Units;
14
+ weight?: number;
15
+ }
16
+ ): FeatureCollection<Point>;
17
+ declare function interpolate(
18
+ points: FeatureCollection<Point>,
19
+ cellSize: number,
20
+ options?: {
21
+ gridType?: Grid;
22
+ property?: string;
23
+ units?: Units;
24
+ weight?: number;
25
+ }
26
+ ): FeatureCollection<Polygon>;
27
+
28
+ export { interpolate as default, interpolate };
@@ -0,0 +1,28 @@
1
+ import { FeatureCollection, Point, Polygon } from 'geojson';
2
+ import { Units, Grid } from '@turf/helpers';
3
+
4
+ /**
5
+ * http://turfjs.org/docs/#interpolate
6
+ */
7
+ declare function interpolate(
8
+ points: FeatureCollection<Point>,
9
+ cellSize: number,
10
+ options?: {
11
+ gridType?: "point";
12
+ property?: string;
13
+ units?: Units;
14
+ weight?: number;
15
+ }
16
+ ): FeatureCollection<Point>;
17
+ declare function interpolate(
18
+ points: FeatureCollection<Point>,
19
+ cellSize: number,
20
+ options?: {
21
+ gridType?: Grid;
22
+ property?: string;
23
+ units?: Units;
24
+ weight?: number;
25
+ }
26
+ ): FeatureCollection<Polygon>;
27
+
28
+ export { interpolate as default, interpolate };
@@ -0,0 +1,87 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.js
5
+ import { bbox } from "@turf/bbox";
6
+ import { hexGrid } from "@turf/hex-grid";
7
+ import { pointGrid } from "@turf/point-grid";
8
+ import { distance } from "@turf/distance";
9
+ import { centroid } from "@turf/centroid";
10
+ import { squareGrid } from "@turf/square-grid";
11
+ import { triangleGrid } from "@turf/triangle-grid";
12
+ import { clone } from "@turf/clone";
13
+ import { featureCollection } from "@turf/helpers";
14
+ import { featureEach } from "@turf/meta";
15
+ import { collectionOf } from "@turf/invariant";
16
+ function interpolate(points, cellSize, options) {
17
+ options = options || {};
18
+ if (typeof options !== "object")
19
+ throw new Error("options is invalid");
20
+ var gridType = options.gridType;
21
+ var property = options.property;
22
+ var weight = options.weight;
23
+ if (!points)
24
+ throw new Error("points is required");
25
+ collectionOf(points, "Point", "input must contain Points");
26
+ if (!cellSize)
27
+ throw new Error("cellSize is required");
28
+ if (weight !== void 0 && typeof weight !== "number")
29
+ throw new Error("weight must be a number");
30
+ property = property || "elevation";
31
+ gridType = gridType || "square";
32
+ weight = weight || 1;
33
+ var box = bbox(points);
34
+ var grid;
35
+ switch (gridType) {
36
+ case "point":
37
+ case "points":
38
+ grid = pointGrid(box, cellSize, options);
39
+ break;
40
+ case "square":
41
+ case "squares":
42
+ grid = squareGrid(box, cellSize, options);
43
+ break;
44
+ case "hex":
45
+ case "hexes":
46
+ grid = hexGrid(box, cellSize, options);
47
+ break;
48
+ case "triangle":
49
+ case "triangles":
50
+ grid = triangleGrid(box, cellSize, options);
51
+ break;
52
+ default:
53
+ throw new Error("invalid gridType");
54
+ }
55
+ var results = [];
56
+ featureEach(grid, function(gridFeature) {
57
+ var zw = 0;
58
+ var sw = 0;
59
+ featureEach(points, function(point) {
60
+ var gridPoint = gridType === "point" ? gridFeature : centroid(gridFeature);
61
+ var d = distance(gridPoint, point, options);
62
+ var zValue;
63
+ if (property !== void 0)
64
+ zValue = point.properties[property];
65
+ if (zValue === void 0)
66
+ zValue = point.geometry.coordinates[2];
67
+ if (zValue === void 0)
68
+ throw new Error("zValue is missing");
69
+ if (d === 0)
70
+ zw = zValue;
71
+ var w = 1 / Math.pow(d, weight);
72
+ sw += w;
73
+ zw += w * zValue;
74
+ });
75
+ var newFeature = clone(gridFeature);
76
+ newFeature.properties[property] = zw / sw;
77
+ results.push(newFeature);
78
+ });
79
+ return featureCollection(results);
80
+ }
81
+ __name(interpolate, "interpolate");
82
+ var turf_interpolate_default = interpolate;
83
+ export {
84
+ turf_interpolate_default as default,
85
+ interpolate
86
+ };
87
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.js"],"sourcesContent":["import { bbox } from \"@turf/bbox\";\nimport { hexGrid } from \"@turf/hex-grid\";\nimport { pointGrid } from \"@turf/point-grid\";\nimport { distance } from \"@turf/distance\";\nimport { centroid } from \"@turf/centroid\";\nimport { squareGrid } from \"@turf/square-grid\";\nimport { triangleGrid } from \"@turf/triangle-grid\";\nimport { clone } from \"@turf/clone\";\nimport { featureCollection } from \"@turf/helpers\";\nimport { featureEach } from \"@turf/meta\";\nimport { collectionOf } from \"@turf/invariant\";\n\n/**\n * Takes a set of points and estimates their 'property' values on a grid using the [Inverse Distance Weighting (IDW) method](https://en.wikipedia.org/wiki/Inverse_distance_weighting).\n *\n * @name interpolate\n * @param {FeatureCollection<Point>} points with known value\n * @param {number} cellSize the distance across each grid point\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.gridType='square'] defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle')\n * @param {string} [options.property='elevation'] the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists.\n * @param {string} [options.units='kilometers'] used in calculating cellSize, can be degrees, radians, miles, or kilometers\n * @param {number} [options.weight=1] exponent regulating the distance-decay weighting\n * @returns {FeatureCollection<Point|Polygon>} grid of points or polygons with interpolated 'property'\n * @example\n * var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]});\n *\n * // add a random property to each point\n * turf.featureEach(points, function(point) {\n * point.properties.solRad = Math.random() * 50;\n * });\n * var options = {gridType: 'points', property: 'solRad', units: 'miles'};\n * var grid = turf.interpolate(points, 100, options);\n *\n * //addToMap\n * var addToMap = [grid];\n */\nfunction interpolate(points, cellSize, options) {\n // Optional parameters\n options = options || {};\n if (typeof options !== \"object\") throw new Error(\"options is invalid\");\n var gridType = options.gridType;\n var property = options.property;\n var weight = options.weight;\n\n // validation\n if (!points) throw new Error(\"points is required\");\n collectionOf(points, \"Point\", \"input must contain Points\");\n if (!cellSize) throw new Error(\"cellSize is required\");\n if (weight !== undefined && typeof weight !== \"number\")\n throw new Error(\"weight must be a number\");\n\n // default values\n property = property || \"elevation\";\n gridType = gridType || \"square\";\n weight = weight || 1;\n\n var box = bbox(points);\n var grid;\n switch (gridType) {\n case \"point\":\n case \"points\":\n grid = pointGrid(box, cellSize, options);\n break;\n case \"square\":\n case \"squares\":\n grid = squareGrid(box, cellSize, options);\n break;\n case \"hex\":\n case \"hexes\":\n grid = hexGrid(box, cellSize, options);\n break;\n case \"triangle\":\n case \"triangles\":\n grid = triangleGrid(box, cellSize, options);\n break;\n default:\n throw new Error(\"invalid gridType\");\n }\n var results = [];\n featureEach(grid, function (gridFeature) {\n var zw = 0;\n var sw = 0;\n // calculate the distance from each input point to the grid points\n featureEach(points, function (point) {\n var gridPoint =\n gridType === \"point\" ? gridFeature : centroid(gridFeature);\n var d = distance(gridPoint, point, options);\n var zValue;\n // property has priority for zValue, fallbacks to 3rd coordinate from geometry\n if (property !== undefined) zValue = point.properties[property];\n if (zValue === undefined) zValue = point.geometry.coordinates[2];\n if (zValue === undefined) throw new Error(\"zValue is missing\");\n if (d === 0) zw = zValue;\n var w = 1.0 / Math.pow(d, weight);\n sw += w;\n zw += w * zValue;\n });\n // write interpolated value for each grid point\n var newFeature = clone(gridFeature);\n newFeature.properties[property] = zw / sw;\n results.push(newFeature);\n });\n return featureCollection(results);\n}\n\nexport { interpolate };\nexport default interpolate;\n"],"mappings":";;;;AAAA,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AACtB,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AA2B7B,SAAS,YAAY,QAAQ,UAAU,SAAS;AAE9C,YAAU,WAAW,CAAC;AACtB,MAAI,OAAO,YAAY;AAAU,UAAM,IAAI,MAAM,oBAAoB;AACrE,MAAI,WAAW,QAAQ;AACvB,MAAI,WAAW,QAAQ;AACvB,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAQ,UAAM,IAAI,MAAM,oBAAoB;AACjD,eAAa,QAAQ,SAAS,2BAA2B;AACzD,MAAI,CAAC;AAAU,UAAM,IAAI,MAAM,sBAAsB;AACrD,MAAI,WAAW,UAAa,OAAO,WAAW;AAC5C,UAAM,IAAI,MAAM,yBAAyB;AAG3C,aAAW,YAAY;AACvB,aAAW,YAAY;AACvB,WAAS,UAAU;AAEnB,MAAI,MAAM,KAAK,MAAM;AACrB,MAAI;AACJ,UAAQ,UAAU;AAAA,IAChB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,UAAU,KAAK,UAAU,OAAO;AACvC;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,aAAO,WAAW,KAAK,UAAU,OAAO;AACxC;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,aAAO,QAAQ,KAAK,UAAU,OAAO;AACrC;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,aAAO,aAAa,KAAK,UAAU,OAAO;AAC1C;AAAA,IACF;AACE,YAAM,IAAI,MAAM,kBAAkB;AAAA,EACtC;AACA,MAAI,UAAU,CAAC;AACf,cAAY,MAAM,SAAU,aAAa;AACvC,QAAI,KAAK;AACT,QAAI,KAAK;AAET,gBAAY,QAAQ,SAAU,OAAO;AACnC,UAAI,YACF,aAAa,UAAU,cAAc,SAAS,WAAW;AAC3D,UAAI,IAAI,SAAS,WAAW,OAAO,OAAO;AAC1C,UAAI;AAEJ,UAAI,aAAa;AAAW,iBAAS,MAAM,WAAW,QAAQ;AAC9D,UAAI,WAAW;AAAW,iBAAS,MAAM,SAAS,YAAY,CAAC;AAC/D,UAAI,WAAW;AAAW,cAAM,IAAI,MAAM,mBAAmB;AAC7D,UAAI,MAAM;AAAG,aAAK;AAClB,UAAI,IAAI,IAAM,KAAK,IAAI,GAAG,MAAM;AAChC,YAAM;AACN,YAAM,IAAI;AAAA,IACZ,CAAC;AAED,QAAI,aAAa,MAAM,WAAW;AAClC,eAAW,WAAW,QAAQ,IAAI,KAAK;AACvC,YAAQ,KAAK,UAAU;AAAA,EACzB,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAnES;AAsET,IAAO,2BAAQ;","names":[]}
package/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Units, Grid } from "@turf/helpers";
4
4
  /**
5
5
  * http://turfjs.org/docs/#interpolate
6
6
  */
7
- export default function interpolate(
7
+ declare function interpolate(
8
8
  points: FeatureCollection<Point>,
9
9
  cellSize: number,
10
10
  options?: {
@@ -14,7 +14,7 @@ export default function interpolate(
14
14
  weight?: number;
15
15
  }
16
16
  ): FeatureCollection<Point>;
17
- export default function interpolate(
17
+ declare function interpolate(
18
18
  points: FeatureCollection<Point>,
19
19
  cellSize: number,
20
20
  options?: {
@@ -24,3 +24,6 @@ export default function interpolate(
24
24
  weight?: number;
25
25
  }
26
26
  ): FeatureCollection<Polygon>;
27
+
28
+ export { interpolate };
29
+ export default interpolate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/interpolate",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.111+08576cb50",
4
4
  "description": "turf interpolate module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -24,53 +24,59 @@
24
24
  "idw",
25
25
  "interpolate"
26
26
  ],
27
- "main": "dist/js/index.js",
28
- "module": "dist/es/index.js",
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
- "types": "./index.d.ts",
33
- "import": "./dist/es/index.js",
34
- "require": "./dist/js/index.js"
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
+ }
35
42
  }
36
43
  },
37
- "types": "index.d.ts",
38
44
  "sideEffects": false,
39
45
  "files": [
40
46
  "dist",
41
47
  "index.d.ts"
42
48
  ],
43
49
  "scripts": {
44
- "bench": "tsx bench.js",
45
- "build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
46
- "docs": "tsx ../../scripts/generate-readmes",
47
- "test": "npm-run-all test:*",
48
- "test:tape": "tsx test.js",
50
+ "bench": "tsx bench.ts",
51
+ "build": "tsup --config ../../tsup.config.ts",
52
+ "docs": "tsx ../../scripts/generate-readmes.ts",
53
+ "test": "npm-run-all --npm-path npm test:*",
54
+ "test:tape": "tsx test.ts",
49
55
  "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
50
56
  },
51
57
  "devDependencies": {
52
- "@turf/truncate": "^7.0.0-alpha.1",
53
- "benchmark": "*",
54
- "chromatism": "*",
55
- "load-json-file": "*",
56
- "npm-run-all": "*",
57
- "rollup": "*",
58
- "tape": "*",
59
- "tsx": "*",
60
- "write-json-file": "*"
58
+ "@turf/truncate": "^7.0.0-alpha.111+08576cb50",
59
+ "benchmark": "^2.1.4",
60
+ "chromatism": "^3.0.0",
61
+ "load-json-file": "^7.0.1",
62
+ "npm-run-all": "^4.1.5",
63
+ "tape": "^5.7.2",
64
+ "tsup": "^8.0.1",
65
+ "tsx": "^4.6.2",
66
+ "write-json-file": "^5.0.0"
61
67
  },
62
68
  "dependencies": {
63
- "@turf/bbox": "^7.0.0-alpha.1",
64
- "@turf/centroid": "^7.0.0-alpha.1",
65
- "@turf/clone": "^7.0.0-alpha.1",
66
- "@turf/distance": "^7.0.0-alpha.1",
67
- "@turf/helpers": "^7.0.0-alpha.1",
68
- "@turf/hex-grid": "^7.0.0-alpha.1",
69
- "@turf/invariant": "^7.0.0-alpha.1",
70
- "@turf/meta": "^7.0.0-alpha.1",
71
- "@turf/point-grid": "^7.0.0-alpha.1",
72
- "@turf/square-grid": "^7.0.0-alpha.1",
73
- "@turf/triangle-grid": "^7.0.0-alpha.1"
69
+ "@turf/bbox": "^7.0.0-alpha.111+08576cb50",
70
+ "@turf/centroid": "^7.0.0-alpha.111+08576cb50",
71
+ "@turf/clone": "^7.0.0-alpha.111+08576cb50",
72
+ "@turf/distance": "^7.0.0-alpha.111+08576cb50",
73
+ "@turf/helpers": "^7.0.0-alpha.111+08576cb50",
74
+ "@turf/hex-grid": "^7.0.0-alpha.111+08576cb50",
75
+ "@turf/invariant": "^7.0.0-alpha.111+08576cb50",
76
+ "@turf/meta": "^7.0.0-alpha.111+08576cb50",
77
+ "@turf/point-grid": "^7.0.0-alpha.111+08576cb50",
78
+ "@turf/square-grid": "^7.0.0-alpha.111+08576cb50",
79
+ "@turf/triangle-grid": "^7.0.0-alpha.111+08576cb50"
74
80
  },
75
- "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
81
+ "gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
76
82
  }
package/dist/es/index.js DELETED
@@ -1,107 +0,0 @@
1
- import bbox from '@turf/bbox';
2
- import hexGrid from '@turf/hex-grid';
3
- import pointGrid from '@turf/point-grid';
4
- import distance from '@turf/distance';
5
- import centroid from '@turf/centroid';
6
- import squareGrid from '@turf/square-grid';
7
- import triangleGrid from '@turf/triangle-grid';
8
- import clone from '@turf/clone';
9
- import { featureCollection } from '@turf/helpers';
10
- import { featureEach } from '@turf/meta';
11
- import { collectionOf } from '@turf/invariant';
12
-
13
- /**
14
- * Takes a set of points and estimates their 'property' values on a grid using the [Inverse Distance Weighting (IDW) method](https://en.wikipedia.org/wiki/Inverse_distance_weighting).
15
- *
16
- * @name interpolate
17
- * @param {FeatureCollection<Point>} points with known value
18
- * @param {number} cellSize the distance across each grid point
19
- * @param {Object} [options={}] Optional parameters
20
- * @param {string} [options.gridType='square'] defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle')
21
- * @param {string} [options.property='elevation'] the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists.
22
- * @param {string} [options.units='kilometers'] used in calculating cellSize, can be degrees, radians, miles, or kilometers
23
- * @param {number} [options.weight=1] exponent regulating the distance-decay weighting
24
- * @returns {FeatureCollection<Point|Polygon>} grid of points or polygons with interpolated 'property'
25
- * @example
26
- * var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]});
27
- *
28
- * // add a random property to each point
29
- * turf.featureEach(points, function(point) {
30
- * point.properties.solRad = Math.random() * 50;
31
- * });
32
- * var options = {gridType: 'points', property: 'solRad', units: 'miles'};
33
- * var grid = turf.interpolate(points, 100, options);
34
- *
35
- * //addToMap
36
- * var addToMap = [grid];
37
- */
38
- function interpolate(points, cellSize, options) {
39
- // Optional parameters
40
- options = options || {};
41
- if (typeof options !== "object") throw new Error("options is invalid");
42
- var gridType = options.gridType;
43
- var property = options.property;
44
- var weight = options.weight;
45
-
46
- // validation
47
- if (!points) throw new Error("points is required");
48
- collectionOf(points, "Point", "input must contain Points");
49
- if (!cellSize) throw new Error("cellSize is required");
50
- if (weight !== undefined && typeof weight !== "number")
51
- throw new Error("weight must be a number");
52
-
53
- // default values
54
- property = property || "elevation";
55
- gridType = gridType || "square";
56
- weight = weight || 1;
57
-
58
- var box = bbox(points);
59
- var grid;
60
- switch (gridType) {
61
- case "point":
62
- case "points":
63
- grid = pointGrid(box, cellSize, options);
64
- break;
65
- case "square":
66
- case "squares":
67
- grid = squareGrid(box, cellSize, options);
68
- break;
69
- case "hex":
70
- case "hexes":
71
- grid = hexGrid(box, cellSize, options);
72
- break;
73
- case "triangle":
74
- case "triangles":
75
- grid = triangleGrid(box, cellSize, options);
76
- break;
77
- default:
78
- throw new Error("invalid gridType");
79
- }
80
- var results = [];
81
- featureEach(grid, function (gridFeature) {
82
- var zw = 0;
83
- var sw = 0;
84
- // calculate the distance from each input point to the grid points
85
- featureEach(points, function (point) {
86
- var gridPoint =
87
- gridType === "point" ? gridFeature : centroid(gridFeature);
88
- var d = distance(gridPoint, point, options);
89
- var zValue;
90
- // property has priority for zValue, fallbacks to 3rd coordinate from geometry
91
- if (property !== undefined) zValue = point.properties[property];
92
- if (zValue === undefined) zValue = point.geometry.coordinates[2];
93
- if (zValue === undefined) throw new Error("zValue is missing");
94
- if (d === 0) zw = zValue;
95
- var w = 1.0 / Math.pow(d, weight);
96
- sw += w;
97
- zw += w * zValue;
98
- });
99
- // write interpolated value for each grid point
100
- var newFeature = clone(gridFeature);
101
- newFeature.properties[property] = zw / sw;
102
- results.push(newFeature);
103
- });
104
- return featureCollection(results);
105
- }
106
-
107
- export default interpolate;
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,121 +0,0 @@
1
- 'use strict';
2
-
3
- var bbox = require('@turf/bbox');
4
- var hexGrid = require('@turf/hex-grid');
5
- var pointGrid = require('@turf/point-grid');
6
- var distance = require('@turf/distance');
7
- var centroid = require('@turf/centroid');
8
- var squareGrid = require('@turf/square-grid');
9
- var triangleGrid = require('@turf/triangle-grid');
10
- var clone = require('@turf/clone');
11
- var helpers = require('@turf/helpers');
12
- var meta = require('@turf/meta');
13
- var invariant = require('@turf/invariant');
14
-
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
-
17
- var bbox__default = /*#__PURE__*/_interopDefaultLegacy(bbox);
18
- var hexGrid__default = /*#__PURE__*/_interopDefaultLegacy(hexGrid);
19
- var pointGrid__default = /*#__PURE__*/_interopDefaultLegacy(pointGrid);
20
- var distance__default = /*#__PURE__*/_interopDefaultLegacy(distance);
21
- var centroid__default = /*#__PURE__*/_interopDefaultLegacy(centroid);
22
- var squareGrid__default = /*#__PURE__*/_interopDefaultLegacy(squareGrid);
23
- var triangleGrid__default = /*#__PURE__*/_interopDefaultLegacy(triangleGrid);
24
- var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
25
-
26
- /**
27
- * Takes a set of points and estimates their 'property' values on a grid using the [Inverse Distance Weighting (IDW) method](https://en.wikipedia.org/wiki/Inverse_distance_weighting).
28
- *
29
- * @name interpolate
30
- * @param {FeatureCollection<Point>} points with known value
31
- * @param {number} cellSize the distance across each grid point
32
- * @param {Object} [options={}] Optional parameters
33
- * @param {string} [options.gridType='square'] defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle')
34
- * @param {string} [options.property='elevation'] the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists.
35
- * @param {string} [options.units='kilometers'] used in calculating cellSize, can be degrees, radians, miles, or kilometers
36
- * @param {number} [options.weight=1] exponent regulating the distance-decay weighting
37
- * @returns {FeatureCollection<Point|Polygon>} grid of points or polygons with interpolated 'property'
38
- * @example
39
- * var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]});
40
- *
41
- * // add a random property to each point
42
- * turf.featureEach(points, function(point) {
43
- * point.properties.solRad = Math.random() * 50;
44
- * });
45
- * var options = {gridType: 'points', property: 'solRad', units: 'miles'};
46
- * var grid = turf.interpolate(points, 100, options);
47
- *
48
- * //addToMap
49
- * var addToMap = [grid];
50
- */
51
- function interpolate(points, cellSize, options) {
52
- // Optional parameters
53
- options = options || {};
54
- if (typeof options !== "object") throw new Error("options is invalid");
55
- var gridType = options.gridType;
56
- var property = options.property;
57
- var weight = options.weight;
58
-
59
- // validation
60
- if (!points) throw new Error("points is required");
61
- invariant.collectionOf(points, "Point", "input must contain Points");
62
- if (!cellSize) throw new Error("cellSize is required");
63
- if (weight !== undefined && typeof weight !== "number")
64
- throw new Error("weight must be a number");
65
-
66
- // default values
67
- property = property || "elevation";
68
- gridType = gridType || "square";
69
- weight = weight || 1;
70
-
71
- var box = bbox__default['default'](points);
72
- var grid;
73
- switch (gridType) {
74
- case "point":
75
- case "points":
76
- grid = pointGrid__default['default'](box, cellSize, options);
77
- break;
78
- case "square":
79
- case "squares":
80
- grid = squareGrid__default['default'](box, cellSize, options);
81
- break;
82
- case "hex":
83
- case "hexes":
84
- grid = hexGrid__default['default'](box, cellSize, options);
85
- break;
86
- case "triangle":
87
- case "triangles":
88
- grid = triangleGrid__default['default'](box, cellSize, options);
89
- break;
90
- default:
91
- throw new Error("invalid gridType");
92
- }
93
- var results = [];
94
- meta.featureEach(grid, function (gridFeature) {
95
- var zw = 0;
96
- var sw = 0;
97
- // calculate the distance from each input point to the grid points
98
- meta.featureEach(points, function (point) {
99
- var gridPoint =
100
- gridType === "point" ? gridFeature : centroid__default['default'](gridFeature);
101
- var d = distance__default['default'](gridPoint, point, options);
102
- var zValue;
103
- // property has priority for zValue, fallbacks to 3rd coordinate from geometry
104
- if (property !== undefined) zValue = point.properties[property];
105
- if (zValue === undefined) zValue = point.geometry.coordinates[2];
106
- if (zValue === undefined) throw new Error("zValue is missing");
107
- if (d === 0) zw = zValue;
108
- var w = 1.0 / Math.pow(d, weight);
109
- sw += w;
110
- zw += w * zValue;
111
- });
112
- // write interpolated value for each grid point
113
- var newFeature = clone__default['default'](gridFeature);
114
- newFeature.properties[property] = zw / sw;
115
- results.push(newFeature);
116
- });
117
- return helpers.featureCollection(results);
118
- }
119
-
120
- module.exports = interpolate;
121
- module.exports.default = interpolate;