From 3b7d6c8ea5a0a76904c9c5f738e3047043a20ae0 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 7 Aug 2014 19:21:35 +0100 Subject: 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. --- .gitignore | 2 + 1.osm | 7 +++ 25.osm | 19 ++++++ 32.osm | 7 +++ 36.osm | 27 +++++++++ 58.osm | 23 +++++++ 59.osm | 23 +++++++ data.yaml | 202 ------------------------------------------------------------- process.js | 66 ++++++++++++++++++++ 9 files changed, 174 insertions(+), 202 deletions(-) create mode 100644 .gitignore create mode 100644 1.osm create mode 100644 25.osm create mode 100644 32.osm create mode 100644 36.osm create mode 100644 58.osm create mode 100644 59.osm delete mode 100644 data.yaml create mode 100755 process.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a9a84c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +~* +data.json diff --git a/1.osm b/1.osm new file mode 100644 index 0000000..7dbb5d8 --- /dev/null +++ b/1.osm @@ -0,0 +1,7 @@ + + + + + + + diff --git a/25.osm b/25.osm new file mode 100644 index 0000000..35bea40 --- /dev/null +++ b/25.osm @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/32.osm b/32.osm new file mode 100644 index 0000000..9318ab5 --- /dev/null +++ b/32.osm @@ -0,0 +1,7 @@ + + + + + + + diff --git a/36.osm b/36.osm new file mode 100644 index 0000000..4246ae1 --- /dev/null +++ b/36.osm @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/58.osm b/58.osm new file mode 100644 index 0000000..adb8edc --- /dev/null +++ b/58.osm @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/59.osm b/59.osm new file mode 100644 index 0000000..6e2e144 --- /dev/null +++ b/59.osm @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data.yaml b/data.yaml deleted file mode 100644 index 92f26ad..0000000 --- a/data.yaml +++ /dev/null @@ -1,202 +0,0 @@ -# This file contains the location of multi-function devices - -## Building 1 - -# PR_B01_C1009_M01 -http://id.southampton.ac.uk/mfd/1811742195: - level: '1' - coordinates: - - -1.3961015 - - 50.9376083 - comment: - Near entrance in far left corner - -## EScience Building - -# PR_B25_R1007_M01 -http://id.southampton.ac.uk/mfd/1811689323: - level: '1' - coordinates: - - -1.3934958 - - 50.9348978 - comment: - Right of entrance in to 1007 - -# PR_B25_R1009_M01 -http://id.southampton.ac.uk/mfd/1811643297: - level: '1' - coordinates: - - -1.3935384 - - 50.9348132 - comment: - Right side of room 1009 - -# PR_B25_R1009_M02 -http://id.southampton.ac.uk/mfd/1811640704: - level: '1' - coordinates: - - -1.3933223 - - 50.9348058 - comment: - Rear of room 1009 - -# PR_B25_R1011_M01 -http://id.southampton.ac.uk/mfd/1811640709: - level: '1' - coordinates: - - -1.3935674 - - 50.9347941 - comment: - Corner of room 1011 - -## Zepler (59) - -# PR_B59_C1730_M01 -http://id.southampton.ac.uk/mfd/1812968319: - level: '1' - coordinates: - - -1.3977322 - - 50.9372873 - comment: - Just outside the rapid prototyping lab - -# PR_B59_R3218_M01 -http://id.southampton.ac.uk/mfd/1812968313: - level: '3' - coordinates: - - -1.3976627 - - 50.9373496 - comment: - Middle of the main corridor on level 3 - -# PR_B59_R3207_M01 -http://id.southampton.ac.uk/mfd/1812950344: - level: '3' - coordinates: - - -1.3977299 - - 50.9372259 - comment: - South end of the Undergraduate Computing Labs, on the left - -# PR_B59_R3237_M01 -http://id.southampton.ac.uk/mfd/1811637593: - level: '3' - coordinates: - - -1.3977482 - - 50.937225 - comment: - South end of the Undergraduate Computing Labs, on the right - - -# PR_B59_R3237_M02 -http://id.southampton.ac.uk/mfd/1811652107: - level: '3' - coordinates: - - -1.3977665 - - 50.9373547 - comment: - Middle of the Undergraduate Computing Labs - -## Library (36) - -# PR_B36_LVL02_M01 -http://id.southampton.ac.uk/mfd/1811643313: - level: '2' - coordinates: - - -1.3957815 - - 50.9348748 - comment: Print room, far right - -# PR_B36_LVL02_M02 -http://id.southampton.ac.uk/mfd/1811689061: - level: '2' - coordinates: - - -1.3957612 - - 50.9348692 - comment: Print room, middle right - -# PR_B36_LVL02_M03 -http://id.southampton.ac.uk/mfd/1811689058: - level: '2' - coordinates: - - -1.395739 - - 50.9348633 - comment: Print room, near right - -# PR_B36_LVL02_M04 -http://id.southampton.ac.uk/mfd/1811689064: - level: '2' - coordinates: - - -1.39575 - - 50.9348476 - comment: Print room, near left - -# PR_B36_LVL02_M05 -http://id.southampton.ac.uk/mfd/1811689068: - level: '2' - coordinates: - - -1.3957726 - - 50.9348536 - comment: Print room, middle right - -# PR_B36_LVL02_M06 -http://id.southampton.ac.uk/mfd/1811689072: - level: '2' - coordinates: - - -1.3957927 - - 50.93486 - comment: Print room, far right - -## Building 32 - -# PR_B32_C3049_M01 -http://id.southampton.ac.uk/mfd/1812956311: - level: '3' - coordinates: - - -1.3958056 - - 50.9361012 - comment: - In the open space, at the south end of level 3 - -## Murray (58) - -# PR_B58_R2126_M01 -http://id.southampton.ac.uk/mfd/1811675031: - level: '2' - coordinates: - - -1.3985114 - - 50.9364605 - comment: In the corridor in the southmost corner of the building - -# PR_B58_R1049_M01 -http://id.southampton.ac.uk/mfd/1811643275: - level: '1' - coordinates: - - -1.3985098 - - 50.9367144 - comment: Named like in room 1049, but actually in room 1043 - -# PR_B58_R1045_M01 -http://id.southampton.ac.uk/mfd/1811643303: - level: '1' - coordinates: - - -1.3984117 - - 50.9366692 - comment: In room 1045 near the partition - -# PR_B58_R1047_M01 -http://id.southampton.ac.uk/mfd/1811643646: - level: '1' - coordinates: - - -1.3983556 - - 50.9365553 - comment: Against the outside wall - -# PR_B58_R1053_M01 -http://id.southampton.ac.uk/mfd/1811643322: - level: '1' - coordinates: - - -1.3986478 - - 50.9364296 - comment: - Against the far outside wall 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(); + }); +}); -- cgit v1.2.3