aboutsummaryrefslogtreecommitdiff
path: root/vicmap2osm.js
blob: e579d981d0d07b13d3b3afa4ae062336eaaed4ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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 args = process.argv.slice(2)

if (args.length < 2) {
  console.error("Usage: ./vicmap2osm.js input.geojson output.geojson")
  process.exit(1)
}

const inputFile = args[0]
const outputFile = args[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)

    // some addresses we skip importing into OSM
    if (filterOSM(osm)) {
      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)
    }
  }
)