Skip to content

Commit

Permalink
Standalone utility for generating metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mojodna committed Jan 19, 2017
1 parent 2424bd5 commit 1c00d0e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
91 changes: 91 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -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] <file>')
.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));
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 1c00d0e

Please sign in to comment.