turf/packages/turf-interpolate
mfedderly a954bf9c21
Migrate @turf/interpolate to TypeScript (#2966)
* Migrate @turf/interpolate to TypeScript

* Fix interpolate type signature for better inference
2025-12-14 06:46:01 -05:00
..
2017-07-11 13:47:48 -04:00
2025-05-16 08:59:12 +02:00

@turf/interpolate

interpolate

Takes a set of points and estimates their 'property' values on a grid using the Inverse Distance Weighting (IDW) method.

Parameters

  • points FeatureCollection<Point> with known value

  • cellSize number the distance across each grid point

  • options Object Optional parameters (optional, default {})

    • options.gridType string defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle') (optional, default 'square')
    • options.property 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 Units used in calculating cellSize. Supports all valid Turf Units. (optional, default 'kilometers')
    • options.weight number exponent regulating the distance-decay weighting (optional, default 1)
    • options.bbox BBox Bounding Box Array [west, south, east, north] associated with the FeatureCollection. (optional, default bbox(points))

Examples

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

Returns FeatureCollection<(Point | Polygon)> grid of points or polygons with interpolated 'property'


This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.

Installation

Install this single module individually:

$ npm install @turf/interpolate

Or install the all-encompassing @turf/turf module that includes all modules as functions:

$ npm install @turf/turf