@turf/interpolate
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,21 +0,25 @@ | ||
/// <reference types="geojson" /> | ||
import { Point, Polygon, Units, FeatureCollection, Grid } from '@turf/helpers'; | ||
import * as helpers from '@turf/helpers'; | ||
/** | ||
* http://turfjs.org/docs/#interpolate | ||
*/ | ||
declare function interpolate( | ||
points: interpolate.Points, | ||
export default function interpolate( | ||
points: FeatureCollection<Point>, | ||
cellSize: number, | ||
outputType: interpolate.OutputTypes, | ||
property?: string, | ||
units?: interpolate.Units, | ||
weight?: number): interpolate.Points; | ||
declare namespace interpolate { | ||
type OutputTypes = 'point' | 'square' | 'hex' | 'triangle'; | ||
type Points = helpers.Points; | ||
type Units = helpers.Units; | ||
} | ||
export = interpolate; | ||
options?: { | ||
gridType?: 'point', | ||
property?: string, | ||
units?: Units, | ||
weight?: number | ||
} | ||
): FeatureCollection<Point>; | ||
export default function interpolate( | ||
points: FeatureCollection<Point>, | ||
cellSize: number, | ||
options?: { | ||
gridType?: Grid, | ||
property?: string, | ||
units?: Units, | ||
weight?: number | ||
} | ||
): FeatureCollection<Polygon>; |
69
index.js
@@ -1,12 +0,12 @@ | ||
var meta = require('@turf/meta'); | ||
var bbox = require('@turf/bbox'); | ||
var hexGrid = require('@turf/hex-grid'); | ||
var poinGrid = require('@turf/point-grid'); | ||
var distance = require('@turf/distance'); | ||
var centroid = require('@turf/centroid'); | ||
var invariant = require('@turf/invariant'); | ||
var squareGrid = require('@turf/square-grid'); | ||
var triangleGrid = require('@turf/triangle-grid'); | ||
var featureEach = meta.featureEach; | ||
var collectionOf = invariant.collectionOf; | ||
import bbox from '@turf/bbox'; | ||
import hexGrid from '@turf/hex-grid'; | ||
import pointGrid from '@turf/point-grid'; | ||
import distance from '@turf/distance'; | ||
import centroid from '@turf/centroid'; | ||
import squareGrid from '@turf/square-grid'; | ||
import triangleGrid from '@turf/triangle-grid'; | ||
import clone from '@turf/clone'; | ||
import { featureCollection } from '@turf/helpers'; | ||
import { featureEach } from '@turf/meta'; | ||
import { collectionOf } from '@turf/invariant'; | ||
@@ -19,11 +19,11 @@ /** | ||
* @param {number} cellSize the distance across each grid point | ||
* @param {string} [gridType='square'] defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle') | ||
* @param {string} [property='elevation'] the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists. | ||
* @param {string} [units=kilometers] used in calculating cellSize, can be degrees, radians, miles, or kilometers | ||
* @param {number} [weight=1] exponent regulating the distance-decay weighting | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.gridType='square'] defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle') | ||
* @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. | ||
* @param {string} [options.units='kilometers'] used in calculating cellSize, can be degrees, radians, miles, or kilometers | ||
* @param {number} [options.weight=1] exponent regulating the distance-decay weighting | ||
* @returns {FeatureCollection<Point|Polygon>} grid of points or polygons with interpolated 'property' | ||
* @example | ||
* var points = turf.random('points', 30, { | ||
* bbox: [50, 30, 70, 50] | ||
* }); | ||
* var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]}); | ||
* | ||
* // add a random property to each point | ||
@@ -33,3 +33,4 @@ * turf.featureEach(points, function(point) { | ||
* }); | ||
* var grid = turf.interpolate(points, 100, 'points', 'solRad', 'miles'); | ||
* var options = {gridType: 'points', property: 'solRad', units: 'miles'}; | ||
* var grid = turf.interpolate(points, 100, options); | ||
* | ||
@@ -39,3 +40,10 @@ * //addToMap | ||
*/ | ||
module.exports = function (points, cellSize, gridType, property, units, weight) { | ||
function interpolate(points, cellSize, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (typeof options !== 'object') throw new Error('options is invalid'); | ||
var gridType = options.gridType; | ||
var property = options.property; | ||
var weight = options.weight; | ||
// validation | ||
@@ -57,15 +65,15 @@ if (!points) throw new Error('points is required'); | ||
case 'points': | ||
grid = poinGrid(box, cellSize, units, true); | ||
grid = pointGrid(box, cellSize, options); | ||
break; | ||
case 'square': | ||
case 'squares': | ||
grid = squareGrid(box, cellSize, units); | ||
grid = squareGrid(box, cellSize, options); | ||
break; | ||
case 'hex': | ||
case 'hexes': | ||
grid = hexGrid(box, cellSize, units); | ||
grid = hexGrid(box, cellSize, options); | ||
break; | ||
case 'triangle': | ||
case 'triangles': | ||
grid = triangleGrid(box, cellSize, units); | ||
grid = triangleGrid(box, cellSize, options); | ||
break; | ||
@@ -75,3 +83,3 @@ default: | ||
} | ||
var results = []; | ||
featureEach(grid, function (gridFeature) { | ||
@@ -83,3 +91,3 @@ var zw = 0; | ||
var gridPoint = (gridType === 'point') ? gridFeature : centroid(gridFeature); | ||
var d = distance(gridPoint, point, units); | ||
var d = distance(gridPoint, point, options); | ||
var zValue; | ||
@@ -96,6 +104,9 @@ // property has priority for zValue, fallbacks to 3rd coordinate from geometry | ||
// write interpolated value for each grid point | ||
gridFeature.properties[property] = zw / sw; | ||
var newFeature = clone(gridFeature); | ||
newFeature.properties[property] = zw / sw; | ||
results.push(newFeature); | ||
}); | ||
return featureCollection(results); | ||
} | ||
return grid; | ||
}; | ||
export default interpolate; |
{ | ||
"name": "@turf/interpolate", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf interpolate module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -34,21 +38,28 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/truncate": "^4.7.3", | ||
"benchmark": "^2.1.4", | ||
"chromatism": "2.6.0", | ||
"load-json-file": "^2.0.0", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.0.0" | ||
"@std/esm": "*", | ||
"@turf/truncate": "^5.0.4", | ||
"benchmark": "*", | ||
"chromatism": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/bbox": "^4.7.3", | ||
"@turf/centroid": "^4.7.3", | ||
"@turf/distance": "^4.7.3", | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/hex-grid": "^4.7.3", | ||
"@turf/invariant": "^4.7.3", | ||
"@turf/meta": "^4.7.3", | ||
"@turf/point-grid": "^4.7.3", | ||
"@turf/square-grid": "^4.7.3", | ||
"@turf/triangle-grid": "^4.7.3" | ||
"@turf/bbox": "^5.0.4", | ||
"@turf/centroid": "^5.0.4", | ||
"@turf/clone": "^5.0.4", | ||
"@turf/distance": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/hex-grid": "^5.0.4", | ||
"@turf/invariant": "^5.0.4", | ||
"@turf/meta": "^5.0.4", | ||
"@turf/point-grid": "^5.0.4", | ||
"@turf/square-grid": "^5.0.4", | ||
"@turf/triangle-grid": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/interpolate | ||
# interpolate | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## interpolate | ||
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). | ||
@@ -11,6 +13,7 @@ | ||
- `cellSize` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the distance across each grid point | ||
- `gridType` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle') (optional, default `'square'`) | ||
- `property` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists. (optional, default `'elevation'`) | ||
- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** used in calculating cellSize, can be degrees, radians, miles, or kilometers (optional, default `kilometers`) | ||
- `weight` **\[[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** exponent regulating the distance-decay weighting (optional, default `1`) | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.gridType` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle') (optional, default `'square'`) | ||
- `options.property` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the property name in `points` from which z-values will be pulled, zValue fallbacks to 3rd coordinate if no property exists. (optional, default `'elevation'`) | ||
- `options.units` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** used in calculating cellSize, can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`) | ||
- `options.weight` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** exponent regulating the distance-decay weighting (optional, default `1`) | ||
@@ -20,5 +23,4 @@ **Examples** | ||
```javascript | ||
var points = turf.random('points', 30, { | ||
bbox: [50, 30, 70, 50] | ||
}); | ||
var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]}); | ||
// add a random property to each point | ||
@@ -28,3 +30,4 @@ turf.featureEach(points, function(point) { | ||
}); | ||
var grid = turf.interpolate(points, 100, 'points', 'solRad', 'miles'); | ||
var options = {gridType: 'points', property: 'solRad', units: 'miles'}; | ||
var grid = turf.interpolate(points, 100, options); | ||
@@ -31,0 +34,0 @@ //addToMap |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15136
6
227
61
11
8
1
+ Added@turf/clone@^5.0.4
+ Added@turf/bbox@5.1.5(transitive)
+ Added@turf/bearing@5.1.5(transitive)
+ Added@turf/boolean-contains@5.1.5(transitive)
+ Added@turf/boolean-overlap@5.1.5(transitive)
+ Added@turf/boolean-point-in-polygon@5.1.5(transitive)
+ Added@turf/boolean-point-on-line@5.1.5(transitive)
+ Added@turf/boolean-within@5.1.5(transitive)
+ Added@turf/centroid@5.1.5(transitive)
+ Added@turf/clean-coords@5.1.5(transitive)
+ Added@turf/clone@5.1.5(transitive)
+ Added@turf/destination@5.1.5(transitive)
+ Added@turf/distance@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/hex-grid@5.1.5(transitive)
+ Added@turf/intersect@5.1.6(transitive)
+ Added@turf/invariant@5.2.0(transitive)
+ Added@turf/line-intersect@5.1.5(transitive)
+ Added@turf/line-overlap@5.1.5(transitive)
+ Added@turf/line-segment@5.1.5(transitive)
+ Added@turf/meta@5.2.0(transitive)
+ Added@turf/nearest-point-on-line@5.1.5(transitive)
+ Added@turf/point-grid@5.1.5(transitive)
+ Added@turf/square-grid@5.1.5(transitive)
+ Added@turf/triangle-grid@5.1.5(transitive)
+ Added@turf/truncate@5.1.5(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddeep-equal@1.1.2(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedgeojson-equality@0.1.6(transitive)
+ Addedgeojson-rbush@2.1.0(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedobject-is@1.1.6(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedquickselect@3.0.0(transitive)
+ Addedrbush@4.0.1(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedturf-jsts@1.2.3(transitive)
- Removed@turf/bbox@4.7.3(transitive)
- Removed@turf/centroid@4.7.3(transitive)
- Removed@turf/distance@4.7.3(transitive)
- Removed@turf/helpers@4.7.3(transitive)
- Removed@turf/hex-grid@4.7.3(transitive)
- Removed@turf/inside@4.7.3(transitive)
- Removed@turf/invariant@4.7.3(transitive)
- Removed@turf/meta@4.7.4(transitive)
- Removed@turf/point-grid@4.7.3(transitive)
- Removed@turf/square-grid@4.7.3(transitive)
- Removed@turf/triangle-grid@4.7.3(transitive)
Updated@turf/bbox@^5.0.4
Updated@turf/centroid@^5.0.4
Updated@turf/distance@^5.0.4
Updated@turf/helpers@^5.0.4
Updated@turf/hex-grid@^5.0.4
Updated@turf/invariant@^5.0.4
Updated@turf/meta@^5.0.4
Updated@turf/point-grid@^5.0.4
Updated@turf/square-grid@^5.0.4
Updated@turf/triangle-grid@^5.0.4