#!/usr/bin/env nodejs var osmtogeojson = require('osmtogeojson'); var fs = require('fs'); var DOMParser = require("xmldom").DOMParser; var async = require('async'); var levels = [1, 3, 4, 5]; async.map(levels, function(level, callback) { fs.readFile('level-' + level + '.osm', 'utf8', function(err, data) { if (err) { callback(err); return; } xml = (new DOMParser()).parseFromString(data, 'text/xml'); var geojson = osmtogeojson(xml, { flatProperties: true, polygonFeatures: function(feature) { return true; } }); var featuresWithLevels = geojson.features.forEach(function(feature) { feature.properties.level = level; }); callback(null, geojson.features); }); }, function(err, features) { var featureCollection = { type: "FeatureCollection", features: [] }; features.forEach(function(featureArray) { featureArray.forEach(function(feature) { delete feature.id; delete feature.properties.id; featureCollection.features.push(feature); }); }); console.log(JSON.stringify(featureCollection, null, 4)); });