UNPKG

@turf/interpolate

Version:

Creates an interpolated grid of points using the Inverse Distance Weighting method.

39 lines (36 loc) 2.02 kB
import { Grid, Units } from '@turf/helpers'; import { FeatureCollection, Point, BBox, Polygon } from 'geojson'; /** * 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). * * @function * @param {FeatureCollection<Point>} points with known value * @param {number} cellSize the distance across each grid point * @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 {Units} [options.units='kilometers'] used in calculating cellSize. Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}. * @param {number} [options.weight=1] exponent regulating the distance-decay weighting * @param {BBox} [options.bbox=bbox(points)] Bounding Box Array [west, south, east, north] associated with the FeatureCollection. * @returns {FeatureCollection<Point|Polygon>} grid of points or polygons with interpolated 'property' * @example * var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]}); * * // add a random property to each point * turf.featureEach(points, function(point) { * point.properties.solRad = Math.random() * 50; * }); * var options = {gridType: 'points', property: 'solRad', units: 'miles'}; * var grid = turf.interpolate(points, 100, options); * * //addToMap * var addToMap = [grid]; */ declare function interpolate<T extends Grid = "square">(points: FeatureCollection<Point>, cellSize: number, options?: { gridType?: T; property?: string; units?: Units; weight?: number; bbox?: BBox; }): FeatureCollection<T extends "point" ? Point : Polygon>; export { interpolate as default, interpolate };