Skip to content

Instantly share code, notes, and snippets.

@dedunumax
Created March 4, 2015 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedunumax/d22b060b1303ce6d6db7 to your computer and use it in GitHub Desktop.
Save dedunumax/d22b060b1303ce6d6db7 to your computer and use it in GitHub Desktop.
KDTree example from NodeJS
/*
* You can download geo.txt from - https://github.com/Adslot/node-puzzle/blob/master/01-geo-lookup/data/geo.txt
*/
var fs = require('fs');
var kd = require('kdtree');
var kdtree = new kd.KDTree(3);
//var kdtree = new kd.KDTree(4);
console.log('Preparing to load values...');
fs.readFileSync('/home/dedunu/kdtree-sample/data/geo.txt').toString().split('\n').forEach(function (line) {
var record = line.split('\t');
kdtree.insert(record[0], record[1], record[3]);
//kdtree.insert(record[0], record[1], record[3], record[4]);
});
console.log('Values are loaded into tree...');
var result = kdtree.nearest(100249600, 100253695);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment