diff --git a/bin/index.js b/bin/index.js new file mode 100644 index 0000000..bc9fc62 --- /dev/null +++ b/bin/index.js @@ -0,0 +1,91 @@ +#!/usr/bin/env node + +var fs = require('fs'); + +var gdalinfo = require('gdalinfo-json'); +var yargs = require('yargs'); + +var applyGdalinfo = require('../lib/apply-gdalinfo'); + +var argv = yargs.usage('Usage: $0 [args] ') + .option('u', { + alias: 'uuid', + describe: 'Source UUID', + requiresArg: true + }) + .option('t', { + alias: 'title', + describe: 'Source title', + requiresArg: true + }) + .option('a', { + alias: 'acquisition-start', + describe: 'Acquisition start date', + requiresArg: true + }) + .option('A', { + alias: 'acquisition-end', + describe: 'Acquisition end date', + requiresArg: true + }) + .option('p', { + alias: 'provider', + describe: 'Provider / owner', + requiresArg: true + }) + .option('P', { + alias: 'platform', + describe: 'Imagery platform (satellite, aircraft, UAV, etc.)', + requiresArg: true + }) + .option('c', { + alias: 'contact', + describe: 'Data provider contact info', + requiresArg: true + }) + .option('m', { + alias: 'additional-metadata', + describe: 'Additional metadata (sensor=WV3, etc.)', + requiresArg: true + }) + .alias({ + help: 'h', + version: 'V' + }) + .demandCommand(1, 1, 'A file must be provided', 'Only one file may be provided') + .help() + .strict() + .version() + .argv; + +var filename = argv._[0]; + +var metadata = { + uuid: argv.uuid, + title: argv.title, + acquisition_start: new Date(argv.acquisitionStart) || null, + acquisition_end: new Date(argv.acquisitionEnd) || null, + platform: argv.platform, + provider: argv.provider, + contact: argv.contact, + properties: argv.additionalMetadata.reduce(function (obj, pair) { + var parts = pair.split("=", 2); + + obj[parts[0]] = parts[1]; + + return obj; + }, {}) +}; + +var stats = fs.statSync(filename); +metadata.file_size = stats.size; + +gdalinfo.local(filename, function (err, oin) { + if (err) { + throw err; + } + + applyGdalinfo(metadata, oin); + + process.stdout.write(JSON.stringify(metadata)); +}); diff --git a/package.json b/package.json index 51eaab1..ff21820 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "description": "A metadata generator for OAM imagery", "main": "index.js", + "bin": "bin/index.js", "scripts": { "test": "./node_modules/semistandard/bin/cmd.js", "start": "node index.js" @@ -28,7 +29,8 @@ "fs-extra": "^0.18.3", "gdalinfo-json": "^0.4.0", "lodash": "^3.8.0", - "s3": "^4.4.0" + "s3": "^4.4.0", + "yargs": "^6.6.0" }, "devDependencies": { "semistandard": "^4.1.4"