Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/interpolate

Package Overview
Dependencies
Maintainers
4
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/interpolate - npm Package Compare versions

Comparing version 4.7.3 to 5.0.4

main.js

36

index.d.ts

@@ -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>;

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc