@turf/interpolate 7.1.0 → 7.3.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 CHANGED
@@ -14,8 +14,9 @@ Takes a set of points and estimates their 'property' values on a grid using the
14
14
 
15
15
  * `options.gridType` **[string][6]** defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle') (optional, default `'square'`)
16
16
  * `options.property` **[string][6]** the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists. (optional, default `'elevation'`)
17
- * `options.units` **[string][6]** used in calculating cellSize, can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
17
+ * `options.units` **Units** used in calculating cellSize. Supports all valid Turf [Units][7]. (optional, default `'kilometers'`)
18
18
  * `options.weight` **[number][4]** exponent regulating the distance-decay weighting (optional, default `1`)
19
+ * `options.bbox` **[BBox][8]** Bounding Box Array \[west, south, east, north] associated with the FeatureCollection. (optional, default `bbox(points)`)
19
20
 
20
21
  ### Examples
21
22
 
@@ -33,7 +34,7 @@ var grid = turf.interpolate(points, 100, options);
33
34
  var addToMap = [grid];
34
35
  ```
35
36
 
36
- Returns **[FeatureCollection][2]<([Point][3] | [Polygon][7])>** grid of points or polygons with interpolated 'property'
37
+ Returns **[FeatureCollection][2]<([Point][3] | [Polygon][9])>** grid of points or polygons with interpolated 'property'
37
38
 
38
39
  [1]: https://en.wikipedia.org/wiki/Inverse_distance_weighting
39
40
 
@@ -47,7 +48,11 @@ Returns **[FeatureCollection][2]<([Point][3] | [Polygon][7])>** grid of points o
47
48
 
48
49
  [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
49
50
 
50
- [7]: https://tools.ietf.org/html/rfc7946#section-3.1.6
51
+ [7]: https://turfjs.org/docs/api/types/Units
52
+
53
+ [8]: https://tools.ietf.org/html/rfc7946#section-5
54
+
55
+ [9]: https://tools.ietf.org/html/rfc7946#section-3.1.6
51
56
 
52
57
  <!-- 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. -->
53
58
 
@@ -12,22 +12,21 @@ var _meta = require('@turf/meta');
12
12
  var _invariant = require('@turf/invariant');
13
13
  function interpolate(points, cellSize, options) {
14
14
  options = options || {};
15
- if (typeof options !== "object")
16
- throw new Error("options is invalid");
15
+ if (typeof options !== "object") throw new Error("options is invalid");
17
16
  var gridType = options.gridType;
18
17
  var property = options.property;
19
18
  var weight = options.weight;
20
- if (!points)
21
- throw new Error("points is required");
19
+ var box = options.bbox;
20
+ if (!points) throw new Error("points is required");
22
21
  _invariant.collectionOf.call(void 0, points, "Point", "input must contain Points");
23
- if (!cellSize)
24
- throw new Error("cellSize is required");
22
+ if (!cellSize) throw new Error("cellSize is required");
25
23
  if (weight !== void 0 && typeof weight !== "number")
26
24
  throw new Error("weight must be a number");
27
25
  property = property || "elevation";
28
26
  gridType = gridType || "square";
29
27
  weight = weight || 1;
30
- var box = _bbox.bbox.call(void 0, points);
28
+ box = box != null ? box : _bbox.bbox.call(void 0, points);
29
+ _helpers.validateBBox.call(void 0, box);
31
30
  var grid;
32
31
  switch (gridType) {
33
32
  case "point":
@@ -57,14 +56,10 @@ function interpolate(points, cellSize, options) {
57
56
  var gridPoint = gridType === "point" ? gridFeature : _centroid.centroid.call(void 0, gridFeature);
58
57
  var d = _distance.distance.call(void 0, gridPoint, point, options);
59
58
  var zValue;
60
- if (property !== void 0)
61
- zValue = point.properties[property];
62
- if (zValue === void 0)
63
- zValue = point.geometry.coordinates[2];
64
- if (zValue === void 0)
65
- throw new Error("zValue is missing");
66
- if (d === 0)
67
- zw = zValue;
59
+ if (property !== void 0) zValue = point.properties[property];
60
+ if (zValue === void 0) zValue = point.geometry.coordinates[2];
61
+ if (zValue === void 0) throw new Error("zValue is missing");
62
+ if (d === 0) zw = zValue;
68
63
  var w = 1 / Math.pow(d, weight);
69
64
  sw += w;
70
65
  zw += w * zValue;
@@ -75,9 +70,9 @@ function interpolate(points, cellSize, options) {
75
70
  });
76
71
  return _helpers.featureCollection.call(void 0, results);
77
72
  }
78
- var turf_interpolate_default = interpolate;
73
+ var index_default = interpolate;
79
74
 
80
75
 
81
76
 
82
- exports.default = turf_interpolate_default; exports.interpolate = interpolate;
77
+ exports.default = index_default; exports.interpolate = interpolate;
83
78
  //# sourceMappingURL=index.cjs.map
@@ -1 +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;AAGA,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"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-interpolate/dist/cjs/index.cjs","../../index.js"],"names":[],"mappings":"AAAA;ACAA,kCAAqB;AACrB,yCAAwB;AACxB,6CAA0B;AAC1B,0CAAyB;AACzB,0CAAyB;AACzB,+CAA2B;AAC3B,mDAA6B;AAC7B,oCAAsB;AACtB,wCAAgD;AAChD,kCAA4B;AAC5B,4CAA6B;AA4B7B,SAAS,WAAA,CAAY,MAAA,EAAQ,QAAA,EAAU,OAAA,EAAS;AAE9C,EAAA,QAAA,EAAU,QAAA,GAAW,CAAC,CAAA;AACtB,EAAA,GAAA,CAAI,OAAO,QAAA,IAAY,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AACrE,EAAA,IAAI,SAAA,EAAW,OAAA,CAAQ,QAAA;AACvB,EAAA,IAAI,SAAA,EAAW,OAAA,CAAQ,QAAA;AACvB,EAAA,IAAI,OAAA,EAAS,OAAA,CAAQ,MAAA;AACrB,EAAA,IAAI,IAAA,EAAM,OAAA,CAAQ,IAAA;AAGlB,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AACjD,EAAA,qCAAA,MAAa,EAAQ,OAAA,EAAS,2BAA2B,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\"@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, validateBBox } 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 * @function\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 {Units} [options.units='kilometers'] used in calculating cellSize. Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}.\n * @param {number} [options.weight=1] exponent regulating the distance-decay weighting\n * @param {BBox} [options.bbox=bbox(points)] Bounding Box Array [west, south, east, north] associated with the FeatureCollection.\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 var box = options.bbox;\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 box = box ?? bbox(points);\n validateBBox(box);\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"]}
@@ -1,4 +1,4 @@
1
- import { FeatureCollection, Point, Polygon } from 'geojson';
1
+ import { FeatureCollection, Point, BBox, Polygon } from 'geojson';
2
2
  import { Units, Grid } from '@turf/helpers';
3
3
 
4
4
  /**
@@ -12,6 +12,7 @@ declare function interpolate(
12
12
  property?: string;
13
13
  units?: Units;
14
14
  weight?: number;
15
+ bbox?: BBox;
15
16
  }
16
17
  ): FeatureCollection<Point>;
17
18
  declare function interpolate(
@@ -22,6 +23,7 @@ declare function interpolate(
22
23
  property?: string;
23
24
  units?: Units;
24
25
  weight?: number;
26
+ bbox?: BBox;
25
27
  }
26
28
  ): FeatureCollection<Polygon>;
27
29
 
@@ -1,4 +1,4 @@
1
- import { FeatureCollection, Point, Polygon } from 'geojson';
1
+ import { FeatureCollection, Point, BBox, Polygon } from 'geojson';
2
2
  import { Units, Grid } from '@turf/helpers';
3
3
 
4
4
  /**
@@ -12,6 +12,7 @@ declare function interpolate(
12
12
  property?: string;
13
13
  units?: Units;
14
14
  weight?: number;
15
+ bbox?: BBox;
15
16
  }
16
17
  ): FeatureCollection<Point>;
17
18
  declare function interpolate(
@@ -22,6 +23,7 @@ declare function interpolate(
22
23
  property?: string;
23
24
  units?: Units;
24
25
  weight?: number;
26
+ bbox?: BBox;
25
27
  }
26
28
  ): FeatureCollection<Polygon>;
27
29
 
package/dist/esm/index.js CHANGED
@@ -7,27 +7,26 @@ import { centroid } from "@turf/centroid";
7
7
  import { squareGrid } from "@turf/square-grid";
8
8
  import { triangleGrid } from "@turf/triangle-grid";
9
9
  import { clone } from "@turf/clone";
10
- import { featureCollection } from "@turf/helpers";
10
+ import { featureCollection, validateBBox } from "@turf/helpers";
11
11
  import { featureEach } from "@turf/meta";
12
12
  import { collectionOf } from "@turf/invariant";
13
13
  function interpolate(points, cellSize, options) {
14
14
  options = options || {};
15
- if (typeof options !== "object")
16
- throw new Error("options is invalid");
15
+ if (typeof options !== "object") throw new Error("options is invalid");
17
16
  var gridType = options.gridType;
18
17
  var property = options.property;
19
18
  var weight = options.weight;
20
- if (!points)
21
- throw new Error("points is required");
19
+ var box = options.bbox;
20
+ if (!points) throw new Error("points is required");
22
21
  collectionOf(points, "Point", "input must contain Points");
23
- if (!cellSize)
24
- throw new Error("cellSize is required");
22
+ if (!cellSize) throw new Error("cellSize is required");
25
23
  if (weight !== void 0 && typeof weight !== "number")
26
24
  throw new Error("weight must be a number");
27
25
  property = property || "elevation";
28
26
  gridType = gridType || "square";
29
27
  weight = weight || 1;
30
- var box = bbox(points);
28
+ box = box != null ? box : bbox(points);
29
+ validateBBox(box);
31
30
  var grid;
32
31
  switch (gridType) {
33
32
  case "point":
@@ -57,14 +56,10 @@ function interpolate(points, cellSize, options) {
57
56
  var gridPoint = gridType === "point" ? gridFeature : centroid(gridFeature);
58
57
  var d = distance(gridPoint, point, options);
59
58
  var zValue;
60
- if (property !== void 0)
61
- zValue = point.properties[property];
62
- if (zValue === void 0)
63
- zValue = point.geometry.coordinates[2];
64
- if (zValue === void 0)
65
- throw new Error("zValue is missing");
66
- if (d === 0)
67
- zw = zValue;
59
+ if (property !== void 0) zValue = point.properties[property];
60
+ if (zValue === void 0) zValue = point.geometry.coordinates[2];
61
+ if (zValue === void 0) throw new Error("zValue is missing");
62
+ if (d === 0) zw = zValue;
68
63
  var w = 1 / Math.pow(d, weight);
69
64
  sw += w;
70
65
  zw += w * zValue;
@@ -75,9 +70,9 @@ function interpolate(points, cellSize, options) {
75
70
  });
76
71
  return featureCollection(results);
77
72
  }
78
- var turf_interpolate_default = interpolate;
73
+ var index_default = interpolate;
79
74
  export {
80
- turf_interpolate_default as default,
75
+ index_default as default,
81
76
  interpolate
82
77
  };
83
78
  //# sourceMappingURL=index.js.map
@@ -1 +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;AAGA,IAAO,2BAAQ;","names":[]}
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, validateBBox } 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 * @function\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 {Units} [options.units='kilometers'] used in calculating cellSize. Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}.\n * @param {number} [options.weight=1] exponent regulating the distance-decay weighting\n * @param {BBox} [options.bbox=bbox(points)] Bounding Box Array [west, south, east, north] associated with the FeatureCollection.\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 var box = options.bbox;\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 box = box ?? bbox(points);\n validateBBox(box);\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,mBAAmB,oBAAoB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AA4B7B,SAAS,YAAY,QAAQ,UAAU,SAAS;AAE9C,YAAU,WAAW,CAAC;AACtB,MAAI,OAAO,YAAY,SAAU,OAAM,IAAI,MAAM,oBAAoB;AACrE,MAAI,WAAW,QAAQ;AACvB,MAAI,WAAW,QAAQ;AACvB,MAAI,SAAS,QAAQ;AACrB,MAAI,MAAM,QAAQ;AAGlB,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,oBAAoB;AACjD,eAAa,QAAQ,SAAS,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AAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAGA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/interpolate",
3
- "version": "7.1.0",
4
- "description": "turf interpolate module",
3
+ "version": "7.3.0",
4
+ "description": "Creates an interpolated grid of points using the Inverse Distance Weighting method.",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
7
7
  "Stefano Borghi <@stebogit>"
@@ -54,31 +54,31 @@
54
54
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
55
55
  },
56
56
  "devDependencies": {
57
- "@turf/truncate": "^7.1.0",
57
+ "@turf/truncate": "7.3.0",
58
58
  "@types/benchmark": "^2.1.5",
59
- "@types/tape": "^4.2.32",
59
+ "@types/tape": "^5.8.1",
60
60
  "benchmark": "^2.1.4",
61
61
  "chromatism": "^3.0.0",
62
62
  "load-json-file": "^7.0.1",
63
63
  "npm-run-all": "^4.1.5",
64
- "tape": "^5.7.2",
65
- "tsup": "^8.0.1",
66
- "tsx": "^4.6.2",
67
- "write-json-file": "^5.0.0"
64
+ "tape": "^5.9.0",
65
+ "tsup": "^8.4.0",
66
+ "tsx": "^4.19.4",
67
+ "write-json-file": "^6.0.0"
68
68
  },
69
69
  "dependencies": {
70
- "@turf/bbox": "^7.1.0",
71
- "@turf/centroid": "^7.1.0",
72
- "@turf/clone": "^7.1.0",
73
- "@turf/distance": "^7.1.0",
74
- "@turf/helpers": "^7.1.0",
75
- "@turf/hex-grid": "^7.1.0",
76
- "@turf/invariant": "^7.1.0",
77
- "@turf/meta": "^7.1.0",
78
- "@turf/point-grid": "^7.1.0",
79
- "@turf/square-grid": "^7.1.0",
80
- "@turf/triangle-grid": "^7.1.0",
70
+ "@turf/bbox": "7.3.0",
71
+ "@turf/centroid": "7.3.0",
72
+ "@turf/clone": "7.3.0",
73
+ "@turf/distance": "7.3.0",
74
+ "@turf/helpers": "7.3.0",
75
+ "@turf/hex-grid": "7.3.0",
76
+ "@turf/invariant": "7.3.0",
77
+ "@turf/meta": "7.3.0",
78
+ "@turf/point-grid": "7.3.0",
79
+ "@turf/square-grid": "7.3.0",
80
+ "@turf/triangle-grid": "7.3.0",
81
81
  "@types/geojson": "^7946.0.10"
82
82
  },
83
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
83
+ "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
84
84
  }