Save output to file in land2geo

This commit is contained in:
wpetit 2021-06-30 15:18:47 +02:00
parent f0f5933e97
commit ca77c01945
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env node
const landxml = require('../bundles/landxml.node.dev');
const fs = require('fs');
const argv = require('yargs')
.scriptName("land2geo")
@ -25,13 +26,23 @@ const argv = require('yargs')
describe: 'the source coordinates projection to use for the LandXML file',
type: 'string'
})
.option('o', {
alias: 'output',
describe: 'the path to the output file. default to stdout',
type: 'string'
})
;
},
handler: argv => {
const converter = new landxml.Converter();
converter.toGeoJSON(argv.file, { projection: argv.projection })
.then(geojson => {
console.log(JSON.stringify(geojson, null, 2));
const data = JSON.stringify(geojson, null, 2);
if (argv.output) {
fs.writeFileSync(argv.output, data);
} else {
console.log(data);
}
})
.catch(err => {
console.error(err);