Today a plain IDW alg. implemented in JS. Tomorrow a Turf.js package? Maybe?
The module has been accepted and is now officially part of TurfJs!
You can find it on Turf's repo or as a stand-alone module on npm
thanks to @tmcw and @morganherlocker.
Obligatory happy celebratory gif:
Takes a set of known sampled points, a property containing data value, an exponent parameter, a cell depth, a unit of measurement and returns a set of square polygons in a grid with an IDW value for each cell.
Based on the Inverse Distance Weighting interpolation algorithm as covered in the following (among other) resources: [1], [2].
parameter | type | description |
---|---|---|
controlPoints |
FeatureCollection | Sampled points with known value |
valueField |
String | GeoJSON field containing the data value to interpolate on |
b |
Number | Exponent regulating the distance weighting |
cellWidth |
Number | The distance across each cell |
units |
String | Used in calculating cellWidth ('miles' or 'kilometers') |
// load IDW
var IDW = require('./index.js')
// load a sample of test points
var fs = require('fs');
var controlPoints = JSON.parse(fs.readFileSync('./data/data.geojson'));
// produce an interpolated surface
var IDWSurface = IDW(controlPoints,'value', 0.5, 0.1,'kilometers');
Requires nodejs.
Git clone
this repo, then require
it
$ npm test
[1] O’Sullivan, D., & Unwin, D. (2010). Geographic Information Analysis (2nd Edition). 432pp. Hoboken, New Jersey (USA): John Wiley & Sons, Inc.
[2] Xiao, N. (2016). GIS Algorithms, 336pp. SAGE Publications Ltd.