45 lines
1.2 KiB
JavaScript
Executable File
45 lines
1.2 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const landxml = require('../bundles/landxml.node.dev');
|
|
|
|
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'
|
|
})
|
|
;
|
|
},
|
|
handler: argv => {
|
|
const converter = new landxml.Converter();
|
|
converter.toGeoJSON(argv.file, { projection: argv.projection })
|
|
.then(geojson => {
|
|
console.log(JSON.stringify(geojson, null, 2));
|
|
})
|
|
.catch(err => {
|
|
console.error(err);
|
|
})
|
|
;
|
|
}
|
|
})
|
|
.demandCommand()
|
|
.help()
|
|
.argv
|