-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
198 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
* `overlap.js` contains `distToler = 0.004` and `overlapPercentage = 0.5`, which are distance between links to be overlap and the overlap percentage between overlap segment and road links (0.5 = 50%). | ||
* `note-generator.js` contains `tolerance = 170` which is tolerance of the angle in degree and is exported to be used by other modules. | ||
The code in this folder is to compare between OS and OSM datasets and find mismatches in oneway road links. The script used to read two input files, then compare road name of each road in first set against all links in second set. If a name match found then compare coordinates if there is an overlap between two links. call function to calculate direction of both links and check if in same or opposite direction. After finishing all links write output to output files. | ||
The first file executed is `comparator.js`, then calls `compareOSroadWithOSM.js` which calls `checker.js` and `direction.js`. `comparator.js` calls `print.js` for printing information to console, `progress.js` called in time intervals to calculate progress of the execution. `io.js` is used to read and write input and output files. | ||
|
||
* `checker.js` contains two parametric values `distToler = 0.004` and `overlapPercent = 0.5` inside function `isOverlapping`, which are distance between links to be overlap and the overlap percentage between overlap segment and road links (0.5 = 50%). | ||
* `direction.js` contains `tolerance = 10` which is tolerance of the angle in degree and is exported to be used by other modules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
//module has 2 function: compareOSroadWithOSM that loop through OSM links, | ||
//prepare output data in arrays and returns number of matches found in OSM for OS link | ||
//linkComparisions function compares two links and return true if direction mismatch found | ||
|
||
const {inRange} = require('./checker.js'); | ||
const {compareNames} = require('./checker.js'); | ||
const {isOverlapping} = require('./checker.js'); | ||
const {calculateAngle} = require('./direction.js') | ||
const {calculateAngle} = require('./direction.js'); | ||
const {isMismatch} = require('./direction.js'); | ||
|
||
let matchesCounter; | ||
let matchesCounter; //counter for howmany matches found in OSM for each OS link | ||
|
||
conditions = (roadOS, roadOSM) => { | ||
//========== compare links, when match check if opposite direction ========== | ||
linkComparisions = (roadOS, roadOSM) => { | ||
const osName = roadOS.properties.name.slice(3, (roadOS.properties.name.length - 1)); | ||
if ( compareNames(osName, roadOSM.properties.name) ) { //comapre if names matches | ||
if ( isOverlapping(roadOS.geometry, roadOSM.geometry) ) { //check if links overlap | ||
matchesCounter ++; //increment links' match counter | ||
let angleOS = calculateAngle(roadOS.geometry.coordinates); //find OS angle | ||
angleOS = roadOS.properties.direction ? angleOS : (angleOS + 180) % 360; //if opposite direction rotate 180 | ||
let angleOSM = calculateAngle(roadOSM.geometry.coordinates); //find OSM angle | ||
angleOS = roadOS.properties.direction ? angleOS : (angleOS + 180) % 360; //if link direction is opposite rotate 180 | ||
const angleOSM = calculateAngle(roadOSM.geometry.coordinates); //find OSM angle | ||
return isMismatch(angleOS, angleOSM); //return true if mismatch occure | ||
} | ||
} | ||
return false; | ||
} | ||
exports.conditions = conditions; | ||
exports.linkComparisions = linkComparisions; //export inner function for unit testing | ||
|
||
//========== loops through OSM data ========== | ||
exports.compareOSroadWithOSM = (roadOS, dataOSM, outputData) => { | ||
matchesCounter = 0; //reset counter for number of matches | ||
|
||
dataOSM.features | ||
.filter(roadOSM => inRange(roadOS, roadOSM)) | ||
.forEach(roadOSM => { | ||
if (conditions(roadOS, roadOSM)) { | ||
let data = { | ||
.filter(roadOSM => inRange(roadOS, roadOSM)) //filter features that are in range | ||
.forEach(roadOSM => { //loop through filter features in range | ||
if (linkComparisions(roadOS, roadOSM)) { //check return value of call to inner function that compare links | ||
let data = { //create object for output file | ||
"roadName": roadOSM.properties.name, | ||
"OSId": (roadOS.properties.id).toString(), | ||
"OSMId": (roadOSM.properties.id).toString(), | ||
}; | ||
outputData.info.push(data); | ||
outputData.OS.push(roadOS); | ||
outputData.OSM.push(roadOSM); | ||
outputData.info.push(data); //push object to info array | ||
outputData.OS.push(roadOS); //push OS link to OS array | ||
outputData.OSM.push(roadOSM); //push OSM link to OSM array | ||
} | ||
}); | ||
|
||
if (matchesCounter === 0) { | ||
if (matchesCounter === 0) { //if number of matches ZERO set to 'noMatch' | ||
matchesCounter = 'noMatch'; | ||
} else if (matchesCounter === 1) { | ||
} else if (matchesCounter === 1) { //if number of matches ONE set to 'oneMatch' | ||
matchesCounter = 'oneMatch'; | ||
} else { | ||
} else { //else set to 'multiMatch' | ||
matchesCounter = 'multiMatch'; | ||
} | ||
return matchesCounter; | ||
return matchesCounter; //return string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
//module for reading and writing files to disk | ||
|
||
const fs = require('fs'); | ||
|
||
//========== read files and return array of data in file ========== | ||
exports.read = (files) => { | ||
if (!files.OS || !files.OSM) { //check file names are given | ||
throw 'ERROR! One or both file names are missing'; //throw error | ||
} | ||
let dataOne = fs.readFileSync(files.OS); //read in OS file first | ||
let dataTwo = fs.readFileSync(files.OSM); //read in OSM file second | ||
dataOne = JSON.parse(dataOne.toString()); //parse OS data | ||
dataTwo = JSON.parse(dataTwo.toString()); //parse OSM data | ||
return [dataOne, dataTwo]; //return array of data from both files | ||
//========== read files and return array of data in file ========== | ||
exports.read = (files) => { | ||
if (!files.OS || !files.OSM) { //check file names are given | ||
throw 'ERROR! One or both file names are missing'; //throw error | ||
} | ||
let dataOne = fs.readFileSync(files.OS); //read in OS file first | ||
let dataTwo = fs.readFileSync(files.OSM); //read in OSM file second | ||
dataOne = JSON.parse(dataOne.toString()); //parse OS data | ||
dataTwo = JSON.parse(dataTwo.toString()); //parse OSM data | ||
return [dataOne, dataTwo]; //return array of data from both files | ||
} | ||
|
||
//========== write data to output files ========== | ||
exports.write = (file = '', data = {}) => { | ||
if (!file || JSON.stringify(data) == '{}') { //check file name given & data not empty | ||
throw 'ERROR! Either file name or data is missing'; //throw error | ||
} | ||
let output = { //add "type" and "feature" keys to make data readible by GIS programmes | ||
"type": "FeatureCollection", | ||
"features": data | ||
}; | ||
fs.writeFileSync(file, JSON.stringify(output, null, 2)); //write data to file | ||
return true; //return true | ||
//========== write data to output files ========== | ||
exports.write = (file = '', data = {}) => { | ||
if (!file || JSON.stringify(data) == '{}') { //check file name given & data not empty | ||
throw 'ERROR! Either file name or data is missing'; //throw error | ||
} | ||
const output = { //add "type" and "feature" keys to make data readible by GIS programmes | ||
"type": "FeatureCollection", | ||
"features": data | ||
}; | ||
fs.writeFileSync(file, JSON.stringify(output, null, 2)); //write data to file | ||
return true; //return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,37 @@ | ||
//module to print information through out the programme | ||
|
||
const tm = require('../time.js'); | ||
|
||
exports.message = (text) => { | ||
console.info(text); | ||
console.info(text); | ||
} | ||
|
||
//========== print info at start of programe ========== | ||
exports.header = (lengthOS, lengthOSM) => { | ||
console.info('\n\t\t*****\t comparator Script started at ' + | ||
new Date().toLocaleTimeString() + ' \t*****\n'); | ||
console.info('Nubmer of roads OS= ' + lengthOS + ', and OSM= ' + lengthOSM); | ||
} | ||
|
||
//========== print info about link matche at end of programe ========== | ||
exports.report = (counter) => { | ||
console.info('Number of OS links with NONE match in OSM: ' + counter.noMatch); | ||
console.info('Number of OS links with ONE match in OSM: ' + counter.oneMatch); | ||
console.info('Number of OS links with MULTImatch in OSM: ' + counter.multiMatch); | ||
console.info('Number of road links without a Name in OS: ' + counter.noName); | ||
} | ||
|
||
//========== print progress info at set intervals ========== | ||
exports.progress = (obj) => { | ||
if (obj.toPrint) { | ||
if (obj.toPrint) { //check if toPrint is true | ||
console.info('Time passed: ' + tm.format(obj.timePassed)); | ||
console.info('Estimate Time Left: ' + tm.format(obj.estimateTimeLeft)); | ||
console.info('Progress: ' + obj.progressPercent.toFixed(2) + '%'); | ||
} | ||
} | ||
|
||
//========== print info at end of programe ========== | ||
exports.footer = (time) => { | ||
let duration = new Date() - time; | ||
console.info('\t***************************************\n'); | ||
console.info('\t\tTotal time taken: \t' + tm.format(new Date() - time) + '\n'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.