Skip to content

Instantly share code, notes, and snippets.

@aaronlidman
Created October 7, 2014 15:50
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 aaronlidman/dbf6ba3d1ea60186c2b4 to your computer and use it in GitHub Desktop.
Save aaronlidman/dbf6ba3d1ea60186c2b4 to your computer and use it in GitHub Desktop.
// storing all nodes and all positions they've ever had
var osmium = require('osmium'),
levelup = require('levelup'),
args = require('minimist')(process.argv.slice(2));
var db;
var reader;
var batch = [];
var batchSize = args.batch || 50000;
if (process.argv[2] === undefined) {
return console.log('specify a file: `node fullHistoryNodeCache.js [planet]`');
}
createDB(args._[0], function() {
readFile(args._[0]);
});
function createDB(name, cb) {
db = levelup('./' + (args.db || 'full-planet-nodes.ldb'), cb);
}
function readFile(file) {
reader = new osmium.Reader(file, {
'node': true
});
readOSM();
}
function readOSM() {
var buffer = reader.read();
if (!buffer) return pushBatch();
while (object = buffer.next()) {
console.log(object);
// batch.push({
// type: "put",
// key: 'n' + object.id,
// value: JSON.stringify(object.lat + ',' + object.lon)
// });
}
readOSM();
// if (batch.length > batchSize) {
// pushBatch(function() {
// readOSM();
// });
// } else {
// readOSM();
// }
}
function pushBatch(callback) {
db.batch(batch, function(err) {
if (err) return console.log(err);
batch = [];
return callback ? callback() : false;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment