Save output to file in land2geo
This commit is contained in:
parent
f0f5933e97
commit
ca77c01945
13
bin/land2geo
13
bin/land2geo
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue