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
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const landxml = require('../bundles/landxml.node.dev');
|
const landxml = require('../bundles/landxml.node.dev');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const argv = require('yargs')
|
const argv = require('yargs')
|
||||||
.scriptName("land2geo")
|
.scriptName("land2geo")
|
||||||
@ -25,13 +26,23 @@ const argv = require('yargs')
|
|||||||
describe: 'the source coordinates projection to use for the LandXML file',
|
describe: 'the source coordinates projection to use for the LandXML file',
|
||||||
type: 'string'
|
type: 'string'
|
||||||
})
|
})
|
||||||
|
.option('o', {
|
||||||
|
alias: 'output',
|
||||||
|
describe: 'the path to the output file. default to stdout',
|
||||||
|
type: 'string'
|
||||||
|
})
|
||||||
;
|
;
|
||||||
},
|
},
|
||||||
handler: argv => {
|
handler: argv => {
|
||||||
const converter = new landxml.Converter();
|
const converter = new landxml.Converter();
|
||||||
converter.toGeoJSON(argv.file, { projection: argv.projection })
|
converter.toGeoJSON(argv.file, { projection: argv.projection })
|
||||||
.then(geojson => {
|
.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 => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user