diff options
author | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-04 16:12:13 +1000 |
---|---|---|
committer | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-04 16:12:13 +1000 |
commit | 4114f6cc1762573ddf05cf92f2d304dbf04ed04e (patch) | |
tree | 4593ff160cac3c426423d3d0b829a2adb90ca805 /bin/vicmap2osm.js | |
parent | 5039b0dbf3af3b93466069927d794f5b1c8ccf81 (diff) |
major refactor and improvements
Diffstat (limited to 'bin/vicmap2osm.js')
-rwxr-xr-x | bin/vicmap2osm.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/bin/vicmap2osm.js b/bin/vicmap2osm.js new file mode 100755 index 0000000..b252f24 --- /dev/null +++ b/bin/vicmap2osm.js @@ -0,0 +1,68 @@ +#!/usr/bin/env node + +const fs = require('fs') +const { Transform, pipeline } = require('readable-stream') +const ndjson = require('ndjson') +const toOSM = require('./toOSM.js') +const filterOSM = require('./filterOSM.js') + +const argv = require('yargs/yargs')(process.argv.slice(2)) + .option('debug', { + type: 'boolean', + description: 'Dumps full debug logs' + }) + .option('tracing', { + type: 'boolean', + description: 'Includes _pfi tags to aid debugging' + }) + .argv + +if (argv._.length < 2) { + console.error("Usage: ./vicmap2osm.js input.geojson output.geojson") + process.exit(1) +} + +const inputFile = argv._[0] +const outputFile = argv._[1] + +if (!fs.existsSync(inputFile)) { + console.error(`${inputFile} not found`) + process.exit(1) +} + +const transform = new Transform({ + readableObjectMode: true, + writableObjectMode: true, + transform(feature, encoding, callback) { + // convert source Feature into a Feature per the OSM schema + const osm = toOSM(feature, { + tracing: argv.tracing + }) + + // some addresses we skip importing into OSM, see README.md#omitted-addresses + if (filterOSM(osm, { + debug: argv.debug + })) { + this.push(osm) + } + + callback() + } +}) + +// stream in source ndjson, transfom and stream out +pipeline( + fs.createReadStream(inputFile), + ndjson.parse(), + transform, + ndjson.stringify(), + fs.createWriteStream(outputFile), + (err) => { + if (err) { + console.log(err) + process.exit(1) + } else { + process.exit(0) + } + } +) |