aboutsummaryrefslogtreecommitdiff
path: root/build-data.js
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-05-04 09:57:44 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-05-22 17:49:00 +0100
commit772439babf4d959881ae905615c70e6a907d46c2 (patch)
tree939fd6244d7b11b86c3e712ba35d4f3ae4418cba /build-data.js
downloadhartley-library-map-data-772439babf4d959881ae905615c70e6a907d46c2.tar
hartley-library-map-data-772439babf4d959881ae905615c70e6a907d46c2.tar.gz
Initial commit
Diffstat (limited to 'build-data.js')
-rwxr-xr-xbuild-data.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/build-data.js b/build-data.js
new file mode 100755
index 0000000..2c24232
--- /dev/null
+++ b/build-data.js
@@ -0,0 +1,47 @@
+#!/usr/bin/env node
+
+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));
+});