1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/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));
});
|