Last active
August 29, 2015 14:03
-
-
Save missinglink/73ae9860f3d16a92b04d to your computer and use it in GitHub Desktop.
osm-pbf-parser / osm-read comparison
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
| // $> npm install osm-pbf-parser osm-read through2 | |
| // $> wget https://s3.amazonaws.com/metro-extracts.mapzen.com/abuja.osm.pbf | |
| var filepath = __dirname + '/abuja.osm.pbf'; | |
| var counts = { | |
| 'osm-pbf-parser': { | |
| node: 0, way: 0, relation: 0 | |
| }, | |
| 'osm-read': { | |
| node: 0, way: 0, bounds: 0 | |
| } | |
| }; | |
| // -- osm-pbf-parser | |
| var parseOSM = require('osm-pbf-parser'); | |
| var fs = require('fs'); | |
| var through = require('through2'); | |
| function runOsmPbfParser(done){ | |
| var osm = parseOSM(); | |
| fs.createReadStream(filepath) | |
| .pipe(osm) | |
| .on( 'end', done ) | |
| .pipe(through.obj(function (row, enc, next) { | |
| row.forEach( function( item ){ | |
| counts['osm-pbf-parser'][item.type]++; | |
| }, this ); | |
| next(); | |
| })) | |
| .on( 'error', console.error.bind(console,'osm-pbf-parser error') ) | |
| ; | |
| } | |
| // -- osm-read | |
| var osmread = require('osm-read'); | |
| function runOsmRead(done){ | |
| osmread.parse({ | |
| filePath: filepath, | |
| endDocument: function(){ | |
| done(); | |
| }, | |
| bounds: function(bounds){ | |
| counts['osm-read'].bounds++; | |
| }, | |
| node: function(node){ | |
| counts['osm-read'].node++; | |
| }, | |
| way: function(way){ | |
| counts['osm-read'].way++; | |
| }, | |
| error: function(msg){ | |
| console.error('osm-read error',msg); | |
| } | |
| }); | |
| } | |
| // -- exec | |
| runOsmPbfParser( function(){ | |
| runOsmRead( function(){ | |
| console.log( 'counts', JSON.stringify( counts, null, 2 ) ); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment