Atlaslog
Atlaslog / Turf.js / Tutorial / Interpolation and grids
Turf.js · Tutorial

Interpolation and grids

Quick answer

This tutorial turns a few sample points into continuous surfaces with turf.interpolate, an inverse-distance weighting grid controlled by cellSize, gridType (point, square or hex) and weight. It also covers isolines for contour levels, tin for triangulated meshes, and hexGrid plus booleanPointInPolygon for per-cell counts. You will be able to generate density grids without exploding memory.

Last verified 2026-11-03 · Turf.js 7.x · Cite this page
Key points
Example
var samples = turf.featureCollection([
  turf.point([116.38, 39.90], { value: 42 }),
  turf.point([116.40, 39.91], { value: 58 }),
  turf.point([116.42, 39.89], { value: 35 }),
  turf.point([116.44, 39.92], { value: 71 })
]);

var grid = turf.interpolate(samples, 0.5, {
  gridType: 'point',        // point | square | hex
  property: 'value',
  units: 'kilometers',
  weight: 2                 // 距离的幂次,越大越「只信近处」
});

console.log(grid.features.length);
console.log(grid.features[0].properties);   // 含 value 插值结果
var lines = turf.isolines(samples, [30, 40, 50, 60, 70], {
  zProperty: 'value',
  commonProperties: { unit: 'μg/m³' }
});

lines.features.forEach(function (f) {
  console.log(f.properties.value, f.geometry.type);
});
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Interpolation and grids. https://www.jingweizhi.com/en/turf/tutorials/interpolation.html (accessed 2026-11-03).