Last active
August 29, 2015 14:06
-
-
Save aaronlidman/2fd6b7c03fc6c60b0032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var osmium = require('osmium'); | |
if (process.stdin.isTTY) { | |
if (process.argv[2] === undefined) { | |
return console.log('specify a file: `node relevant.js [file].osc` or a list of files: `ls *.osc | node relevant.js`'); | |
} | |
console.log(process.argv[2]); | |
relevant(process.argv[2]); | |
} else { | |
process.stdin.on('readable', function() { | |
var buf = process.stdin.read(); | |
if (buf === null) return; | |
buf.toString().split('\n').forEach(function(file) { | |
if (file.length) relevant(file); | |
}); | |
}); | |
} | |
function relevant(file) { | |
var reader = new osmium.Reader(file, { | |
'node': true, | |
'way': true | |
}); | |
var handler = new osmium.Handler(); | |
// handler.options({'tagged_nodes_only': true}); | |
handler.on('node', function(node) { | |
// console.log(node); | |
}); | |
handler.on('way', function(way) { | |
console.log(way); | |
}); | |
// reader.apply(handler); | |
osmium.apply(reader, handler, new osmium.LocationHandler('disk')); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var osmium = require('osmium'); | |
levelup = require('levelup'); | |
var db = levelup('./' + (process.argv[3] || 'test.ldb')); | |
var count = 0; | |
var batch = []; | |
var batchSize = 100000; | |
var reader = new osmium.Reader(process.argv[2], { | |
'node': true, | |
'way': true | |
}); | |
function nextBuffer() { | |
var buffer = reader.read(); | |
if (!buffer) return pushBatch(batch); | |
while (object = buffer.next()) { | |
var type = ('nodes_count' in object) ? 'w' : 'n'; | |
batch.push({ | |
type: 'put', | |
key: type + object.id, | |
value: JSON.stringify(object) | |
}); | |
} | |
if (batch.length > batchSize) { | |
pushBatch(batch, nextBuffer); | |
} else { | |
nextBuffer(); | |
} | |
count++; | |
} | |
function pushBatch(array, callback) { | |
db.batch(array, function(err) { | |
if (err) return console.log(err); | |
batch = []; | |
return callback ? callback() : false; | |
}); | |
} | |
nextBuffer(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "openstreetreports", | |
"version": "0.0.0", | |
"description": "", | |
"main": "", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "BSD", | |
"dependencies": { | |
"leveldown": "^0.10.1", | |
"levelup": "^0.19.0", | |
"osmium": "^0.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment