Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

pull vis metadata configs on build

Jason Kent7b85add4479c
diff --git a/tasks/buildOptions.sh b/tasks/buildOptions.sh
index ba4232a7a..11659e6df 100755
--- a/tasks/buildOptions.sh
+++ b/tasks/buildOptions.sh
@@ -129,6 +129,10 @@ if [ ! -e "$BUILD_DIR/config/wv.json/categoryGroupOrder.json" ] ; then
"$SRC_DIR/common/config/wv.json/"
fi
+# Run getVisMetadata.py to fetch visualization (layer) metadata
+"$PYTHON_SCRIPTS_DIR/getVisMetadata.py" "$BUILD_DIR/config/wv.json/layerOrder.json" \
+ "$BUILD_DIR/config/wv.json/visMetadata.json"
+
# Run mergeConfig.py on all directories in /config
configs=$(ls "$BUILD_DIR/config")
for config in $configs; do
@@ -143,8 +147,10 @@ for config in $configs; do
esac
done
+# Run mergeConfigWithWMTS.py to merge layer metadata from WMTS GC with worldview layer configs into wv.json
"$PYTHON_SCRIPTS_DIR/mergeConfigWithWMTS.py" "$BUILD_DIR/_wmts" \
"$DEST_DIR/config/wv.json"
+
# Copy brand files from build to dest
cp -r "$BUILD_DIR/brand" "$DEST_DIR"
cp "$BUILD_DIR/brand.json" "$DEST_DIR"
diff --git a/tasks/python3/extractConfigFromWMTS.py b/tasks/python3/extractConfigFromWMTS.py
index e027bca85..c7e8d6705 100755
--- a/tasks/python3/extractConfigFromWMTS.py
+++ b/tasks/python3/extractConfigFromWMTS.py
@@ -14,7 +14,7 @@ prog = os.path.basename(__file__)
base_dir = os.path.join(os.path.dirname(__file__), "..")
version = "2.0.0"
help_description = """\
-Extracts configuration information from a WMTS GetCapabilities file.
+Extracts configuration information from a WMTS GetCapabilities file, converts the XML to JSON
"""
parser = OptionParser(usage="Usage: %s <config_file> <input_dir> <output_dir>" % prog,
diff --git a/tasks/python3/getCapabilities.py b/tasks/python3/getCapabilities.py
index 8f177ed2b..a9af73ea6 100755
--- a/tasks/python3/getCapabilities.py
+++ b/tasks/python3/getCapabilities.py
@@ -16,7 +16,7 @@ prog = os.path.basename(__file__)
base_dir = os.path.join(os.path.dirname(__file__), "..")
version = "1.0.0"
help_description = """\
-Fetches options from remote locations
+Pulls GetCapabilities XML and linked metadata from configured locations
"""
parser = OptionParser(usage="Usage: %s <config> <output_dir>" % prog,
diff --git a/tasks/python3/getVisMetadata.py b/tasks/python3/getVisMetadata.py
new file mode 100755
index 000000000..907e34499
--- /dev/null
+++ b/tasks/python3/getVisMetadata.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+from concurrent.futures import ThreadPoolExecutor
+from optparse import OptionParser
+from pprint import pprint as pp
+from util import dict_merge
+import os
+import json
+import sys
+import urllib3
+import certifi
+http = urllib3.PoolManager(
+ cert_reqs='CERT_REQUIRED',
+ ca_certs=certifi.where()
+ )
+prog = os.path.basename(__file__)
+
+gibs_url = 'localhost:8080/layer-metadata/v1.0/'
+
+parser = OptionParser(usage="Usage: %s <input_file> <output_file>" % prog)
+(options, args) = parser.parse_args()
+input_file = args[0]
+output_file = args[1]
+layer_metadata = {}
+
+def get_metadata(layer_id):
+ response = http.request('GET', gibs_url + layer_id + '.json')
+ layer_metadata[layer_id] = json.loads(response.data.decode('utf-8'))
+
+#MAIN
+if __name__ == "__main__":
+ with open(input_file, 'rt') as layer_order:
+ layer_ids = json.load(layer_order).get('layerOrder')
+ print('%s: Pulling vis metadata for %s layers... ' % (prog, len(layer_ids)))
+
+ futures = []
+ with ThreadPoolExecutor() as executor:
+ for layer in layer_ids:
+ futures.append(executor.submit(get_metadata, layer))
+ for f in futures:
+ try:
+ # Need to call result() on each future to catch any raised exceptions
+ f.result()
+ except Exception as e:
+ print("%s:" % (e))
+
+ with open(output_file, "w") as fp:
+ # Format of this object will determine how this data is combined into wv.json
+ json.dump({ 'layers': layer_metadata}, fp, indent=2, sort_keys=True)
\ No newline at end of file