2020-12-10 16:54:02 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const landxml = require('../bundles/landxml.node.dev');
|
2021-06-30 15:18:47 +02:00
|
|
|
const fs = require('fs');
|
2020-12-10 16:54:02 +01:00
|
|
|
|
|
|
|
const argv = require('yargs')
|
|
|
|
.scriptName("land2geo")
|
|
|
|
.usage('$0 <cmd> [args]')
|
|
|
|
.command('convert <file>', 'convert a LandXML file to GeoJSON', {
|
|
|
|
alias: 'projection',
|
|
|
|
default: landxml.PROJECTION_AUTO_DETECT,
|
|
|
|
describe: 'use the specified source projection',
|
|
|
|
type: 'string',
|
|
|
|
builder: yargs => {
|
|
|
|
yargs
|
|
|
|
.positional('file', {
|
|
|
|
describe: 'the LandXML file to convert',
|
|
|
|
type: 'string'
|
|
|
|
})
|
|
|
|
.require('file')
|
|
|
|
.coerce('file', function (arg) {
|
|
|
|
return require('fs').readFileSync(arg, 'utf8')
|
|
|
|
})
|
|
|
|
.option('p', {
|
|
|
|
alias: 'projection',
|
|
|
|
describe: 'the source coordinates projection to use for the LandXML file',
|
|
|
|
type: 'string'
|
|
|
|
})
|
2021-06-30 15:18:47 +02:00
|
|
|
.option('o', {
|
|
|
|
alias: 'output',
|
|
|
|
describe: 'the path to the output file. default to stdout',
|
|
|
|
type: 'string'
|
|
|
|
})
|
2020-12-10 16:54:02 +01:00
|
|
|
;
|
|
|
|
},
|
|
|
|
handler: argv => {
|
|
|
|
const converter = new landxml.Converter();
|
|
|
|
converter.toGeoJSON(argv.file, { projection: argv.projection })
|
|
|
|
.then(geojson => {
|
2021-06-30 15:18:47 +02:00
|
|
|
const data = JSON.stringify(geojson, null, 2);
|
|
|
|
if (argv.output) {
|
|
|
|
fs.writeFileSync(argv.output, data);
|
|
|
|
} else {
|
|
|
|
console.log(data);
|
|
|
|
}
|
2020-12-10 16:54:02 +01:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.demandCommand()
|
|
|
|
.help()
|
|
|
|
.argv
|