forked from openimagerynetwork/oin-meta-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone utility for generating metadata
Refs openimagerynetwork#2
- Loading branch information
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters