Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-739: Colormaps now obtained from link provided in GetCapabilities document for GIBS WMTS services

Mike McGann6b24e3cf5e2f
diff --git a/LICENSE.md b/LICENSE.md
index 3108b5587..6994d7c54 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -256,4 +256,4 @@ to all terms and conditions herein.
**F. Point of Contact:** Any Recipient contact with Government Agency is to be
directed to the designated representative as follows: Enidia Santiago-Arce,
-SRA Assistant, (301) 286-8497
\ No newline at end of file
+SRA Assistant, (301) 286-8497
diff --git a/bin/wv-options-build b/bin/wv-options-build
index 3a767ea3f..d628c0455 100755
--- a/bin/wv-options-build
+++ b/bin/wv-options-build
@@ -18,7 +18,7 @@ SRC_DIR="$BASE/options"
BUILD_DIR="$BASE/build/options-build"
DEST_DIR="$BASE/build/options"
-set -e
+[ "$FORCE" ] || set -e
die() {
echo "$PROG: ERROR: $@" >& 2
@@ -41,7 +41,7 @@ fi
if [ -e "$BUILD_DIR/config.json" ] ; then
"$BIN_DIR/wv-options-fetch" "$BUILD_DIR/config.json" "$BUILD_DIR/fetch"
"$BIN_DIR/wv-options-wmts" "$BUILD_DIR/config.json" "$BUILD_DIR/fetch" \
- "$BUILD_DIR/config/wv.json/_wmts"
+ "$BUILD_DIR/config/wv.json/_wmts" "$BUILD_DIR/colormaps"
fi
if [ -e "$BUILD_DIR/colormaps" ] ; then
mkdir -p "$BUILD_DIR"/config/palettes
diff --git a/bin/wv-options-validate b/bin/wv-options-validate
index 2f6635a41..07689ad34 100755
--- a/bin/wv-options-validate
+++ b/bin/wv-options-validate
@@ -63,11 +63,16 @@ for layer_id in wv["layers"].keys():
if "warnOnUnexpectedLayer" in opt:
warn("[%s] Unexpected layer" % layer_id)
del wv["layers"][layer_id]
+ continue
if "palette" in layer:
palette_id = layer["palette"]["id"]
if not os.path.exists(os.path.join(config_dir, "palettes",
palette_id + ".json")):
error("[%s] Unknown palette: %s" % (layer_id, palette_id))
+ if "group" not in layer:
+ error("[%s] No group defined" % palette_id)
+ del wv["layers"][layer_id]
+ continue
for layer_id in wv["layerOrder"]:
if layer_id not in wv["layers"]:
diff --git a/bin/wv-options-wmts b/bin/wv-options-wmts
index 219881954..0c3538e35 100755
--- a/bin/wv-options-wmts
+++ b/bin/wv-options-wmts
@@ -15,6 +15,7 @@ import json
from optparse import OptionParser
import os
import sys
+import urllib2 as urllib
import xmltodict
prog = os.path.basename(__file__)
@@ -24,17 +25,18 @@ help_description = """\
Extracts configuration information from a WMTS GetCapabilities file.
"""
-parser = OptionParser(usage="Usage: %s <config_file> <input_dir> <output_dir>" % prog,
+parser = OptionParser(usage="Usage: %s <config_file> <input_dir> <output_dir> <colormaps_dir>" % prog,
version="%s version %s" % (prog, version),
epilog=help_description)
(options, args) = parser.parse_args()
-if len(args) != 3:
+if len(args) != 4:
parser.error("Invalid number of arguments")
config_file = args[0]
input_dir = args[1]
output_dir = args[2]
+colormaps_dir = args[3]
with open(config_file) as fp:
config = json.load(fp)
@@ -54,10 +56,14 @@ total_layer_count = 0
total_warning_count = 0
total_error_count = 0
+json_options = {}
+json_options["indent"] = 4
+json_options["separators"] = (',', ': ')
+
class SkipException(Exception):
pass
-def process_layer(gc_layer, wv_layers):
+def process_layer(gc_layer, wv_layers, colormaps):
id = gc_layer["ows:Identifier"]
if id in skip:
raise SkipException(id)
@@ -95,8 +101,19 @@ def process_layer(gc_layer, wv_layers):
"matrixSet": matrixSet
}
}
+
+ # Colormap links
+ if "ows:Metadata" in gc_layer:
+ # FIXME: Assumes that there is only one metdata element
+ colormap_link = gc_layer["ows:Metadata"]["@xlink:href"]
+ colormap_file = os.path.basename(colormap_link)
+ colormap_id = os.path.splitext(colormap_file)[0]
+ colormaps[colormap_id] = colormap_link
+ wv_layer["palette"] = {
+ "id": colormap_id
+ }
-def process_entry(entry):
+def process_entry(entry, colormaps):
layer_count = 0
warning_count = 0
error_count = 0
@@ -121,7 +138,7 @@ def process_entry(entry):
id = gc_layer["ows:Identifier"]
try:
layer_count += 1
- process_layer(gc_layer, wv_layers)
+ process_layer(gc_layer, wv_layers, colormaps)
except SkipException as se:
warning_count += 1
sys.stderr.write("%s: WARNING: [%s] Skipping\n" % (prog, id))
@@ -146,25 +163,41 @@ def process_entry(entry):
]
}
- json_options = {}
- json_options["indent"] = 4
- json_options["separators"] = (',', ': ')
-
output_file = os.path.join(output_dir, entry["to"])
with open(output_file, "w") as fp:
json.dump(wv, fp, **json_options)
-
print "%s: %d error(s), %d warning(s), %d layers for %s" % (prog,
error_count, warning_count, layer_count, entry["source"])
return [error_count, warning_count, layer_count]
+def fetch_colormaps(colormaps):
+ print "%s: Fetching %d colormaps" % (prog, len(colormaps))
+ sys.stdout.flush()
+ errors = 0
+ for link in colormaps.values():
+ try:
+ response = urllib.urlopen(link)
+ contents = response.read()
+ output_file = os.path.join(colormaps_dir, os.path.basename(link))
+ with open(output_file, "w") as fp:
+ fp.write(contents)
+ except Exception as e:
+ errors += 1
+ sys.stderr.write("%s: ERROR: Unable to fetch %s: %s" %
+ (prog, link, str(e)))
+
+ return errors
+
# Main
+colormaps = {}
for entry in entries:
- error_count, warning_count, layer_count = process_entry(entry)
+ error_count, warning_count, layer_count = process_entry(entry, colormaps)
total_error_count += error_count
total_warning_count += warning_count
total_layer_count += layer_count
+total_error_count += fetch_colormaps(colormaps)
+
print "%s: %d error(s), %d warning(s), %d layers" % (prog, total_error_count,
total_warning_count, total_layer_count)
diff --git a/src/index.html b/src/index.html
index d51a09a0a..cfd809456 100644
--- a/src/index.html
+++ b/src/index.html
@@ -195,6 +195,7 @@
<!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.ui.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/wv.tour.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/wv.debug.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/wv.main.js"></script>
</head>
diff --git a/src/js/wv.debug.js b/src/js/wv.debug.js
index 3609d5b1d..9007355f8 100644
--- a/src/js/wv.debug.js
+++ b/src/js/wv.debug.js
@@ -139,7 +139,7 @@ wv.debug.layers = wv.debug.layers || function(ui, models, config) {
if ( !layer.projections[proj] ) {
return false;
}
- if ( layer.id === "land_water_map" || layer.id === "land_mask" ) {
+ if ( layer.id === "Land_Water_Map" || layer.id === "Land_Mask" ) {
return false;
}
if ( type === "gibs" && layer.period === "daily" && layer.type === "wmts" ) {
@@ -163,21 +163,24 @@ wv.debug.layers = wv.debug.layers || function(ui, models, config) {
$select.empty();
var proj = models.proj.selected.id;
var sortedLayers = _.sortBy(config.layers, ["title", "subtitle"]);
+ console.log(config.layers);
+ console.log(sortedLayers);
_.each(sortedLayers, function(layer) {
if ( acceptLayer(layer) ) {
var text = layer.title + "; " + layer.subtitle;
if ( text.length > 65 ) {
text = text.substr(0, 65) + "...";
}
- var option = $("<option></option>")
+ console.log(layer.id);
+ var $option = $("<option></option>")
.val(layer.id)
.html(text);
- $select.append(option);
+ $select.append($option);
}
});
models.layers.clear();
if ( type !== "gibs" ) {
- models.layers.add("land_water_map");
+ models.layers.add("Land_Water_Map");
}
updateLayers.apply($select);
if ( type === "dataDownload" ) {
diff --git a/src/js/wv.main.js b/src/js/wv.main.js
index 45c8e4362..5c5ce91e8 100644
--- a/src/js/wv.main.js
+++ b/src/js/wv.main.js
@@ -208,7 +208,7 @@ $(function() {
} else {
console.warn("Development version");
}
- //wv.debug.layers(ui, models, config);
+ wv.debug.layers(ui, models, config);
errorReport();
//wv.debug.error(parameters);