aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Harvey <andrew@alantgeo.com.au>2021-05-26 13:19:13 +1000
committerAndrew Harvey <andrew@alantgeo.com.au>2021-05-26 13:19:13 +1000
commit411a9e221e30746f45b7cf89867291d8c755fe39 (patch)
tree28ae493b7782cf696abb3ca996fba90688406681
parent974b530f9fbd3ebe9c3638a7071692f9085eb46e (diff)
add rough script to find potential abbreviated addr:street types and suggest fixes for maproulette
-rwxr-xr-xbin/findAbbrStreets.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/bin/findAbbrStreets.js b/bin/findAbbrStreets.js
new file mode 100755
index 0000000..67e5813
--- /dev/null
+++ b/bin/findAbbrStreets.js
@@ -0,0 +1,107 @@
+#!/usr/bin/env node
+
+/**
+ * Find OSM streets with abbreviated street types
+ */
+
+const fs = require('fs')
+const { Transform, pipeline } = require('stream')
+const ndjson = require('ndjson')
+
+const argv = require('yargs/yargs')(process.argv.slice(2))
+ .argv
+
+if (argv._.length < 2) {
+ console.error("Usage: ./findAbbrStreets.js input.geojson output.geojson")
+ process.exit(1)
+}
+
+const inputFile = argv._[0]
+const outputFile = argv._[1]
+
+const abbreviatedTypes = ['rd', 'st', 'ave', 'av', 'ln', 'cl', 'hwy', 'pl']
+const streetTypes = {
+ 'rd': 'Road',
+ 'st': 'Street',
+ 'ave': 'Avenue',
+ 'av': 'Avenue',
+ 'ln': 'Lane',
+ 'cl': 'Close',
+ 'hwy': 'Highway',
+ 'pl': 'Place'
+}
+
+if (!fs.existsSync(inputFile)) {
+ console.error(`${inputFile} not found`)
+ process.exit(1)
+}
+
+let index = 0
+const checkStreet = new Transform({
+ readableObjectMode: true,
+ writableObjectMode: true,
+ transform(feature, encoding, callback) {
+ index++
+
+ if (process.stdout.isTTY && index % 10000 === 0) {
+ process.stdout.write(` ${index.toLocaleString()}\r`)
+ }
+
+ if ('addr:street' in feature.properties) {
+ const street = feature.properties['addr:street'].toLowerCase()
+ const streetEndsWithAbbr = abbreviatedTypes.map(ab => street.endsWith(` ${ab}`)).reduce((acc, cur) => acc || cur)
+ if (streetEndsWithAbbr) {
+ const matches = street.match(/ (rd|st|ave|av|ln|cl|hwy|pl)$/)
+ if (matches.length) {
+ const ab = matches[1]
+ const expandedStreetType = streetTypes[ab]
+ const fullStreetName = feature.properties['addr:street'].replace(/ (rd|st|ave|av|ln|cl|hwy|pl)$/i, ` ${expandedStreetType}`)
+
+ // MapRoulette task
+ const task = {
+ type: 'FeatureCollection',
+ features: [ feature ],
+ cooperativeWork: {
+ meta: {
+ version: 2,
+ type: 1 // tag fix type
+ },
+ operations: [{
+ operationType: 'modifyElement',
+ data: {
+ id: `${feature.properties['@type']}/${feature.properties['@id']}`,
+ operations: [{
+ operation: 'setTags',
+ data: {
+ 'addr:street': fullStreetName
+ }
+ }]
+ }
+ }]
+ }
+ }
+ this.push(task)
+ }
+ // this.push(feature)
+ }
+ }
+
+ callback()
+ }
+})
+
+pipeline(
+ fs.createReadStream(inputFile),
+ ndjson.parse(),
+ checkStreet,
+ ndjson.stringify(),
+ fs.createWriteStream(outputFile),
+ err => {
+ if (err) {
+ console.log(err)
+ process.exit(1)
+ } else {
+ process.exit(0)
+ }
+ }
+)