aboutsummaryrefslogtreecommitdiff
path: root/process.js
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-08-07 19:21:35 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-08-07 19:21:35 +0100
commit3b7d6c8ea5a0a76904c9c5f738e3047043a20ae0 (patch)
tree12b2cb77b67faa9563bf6c590ddc36fb4bed79f0 /process.js
parentfe7f0b1e4485347eb995f36db80ba62965317fbf (diff)
downloadmfd-location-3b7d6c8ea5a0a76904c9c5f738e3047043a20ae0.tar
mfd-location-3b7d6c8ea5a0a76904c9c5f738e3047043a20ae0.tar.gz
Change format from YAML to OSM XML
The yaml file was hard to edit, using OSM XML allows the use of JOSM as an editor.
Diffstat (limited to 'process.js')
-rwxr-xr-xprocess.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/process.js b/process.js
new file mode 100755
index 0000000..4054106
--- /dev/null
+++ b/process.js
@@ -0,0 +1,66 @@
+#!/usr/bin/env nodejs
+
+fs = require('fs')
+osmtogeojson = require('osmtogeojson');
+
+DOMParser = require('xmldom').DOMParser;
+
+if (!String.prototype.endsWith) {
+ Object.defineProperty(String.prototype, 'endsWith', {
+ value: function (searchString, position) {
+ var subjectString = this.toString();
+ if (position === undefined || position > subjectString.length) {
+ position = subjectString.length;
+ }
+ position -= searchString.length;
+ var lastIndex = subjectString.indexOf(searchString, position);
+ return lastIndex !== -1 && lastIndex === position;
+ }
+ });
+}
+
+fs.readdir('.', function(err, files) {
+ var features = [];
+
+ files.forEach(function(name) {
+ if (name.endsWith(".osm")) {
+ buildingId = name.slice(0, -4);
+
+ data = fs.readFileSync(name, 'utf8');
+
+ var doc = new DOMParser().parseFromString(data);
+
+ var geojson = osmtogeojson(doc, {
+ flatProperties: true
+ });
+
+ geojson.features.forEach(function(feature) {
+ delete feature.id
+ delete feature.properties.id
+
+ features.push(feature);
+ });
+ }
+ });
+
+ var byURI = {};
+
+ features.forEach(function(feature) {
+ if (feature.properties.uri in byURI) {
+ console.error("duplicate uri " + feature.properties.uri);
+ } else {
+ byURI[feature.properties.uri] = feature;
+ }
+ });
+
+ featureCollection = {
+ type: "FeatureCollection",
+ features: features
+ };
+
+ var stream = fs.createWriteStream("./data.json");
+ stream.once('open', function(fd) {
+ stream.write(JSON.stringify(featureCollection, null, 4));
+ stream.end();
+ });
+});