def process_layer(gc_layer, wv_layers, colormaps): ident = gc_layer["ows:Identifier"] if ident in skip: print "%s: skipping" % ident raise SkipException(ident) wv_layers[ident] = {} wv_layer = wv_layers[ident] wv_layer["id"] = ident wv_layer["type"] = "wmts" wv_layer["format"] = gc_layer["Format"] # Extract start and end dates if "Dimension" in gc_layer: dimension = gc_layer["Dimension"] if dimension["ows:Identifier"] == "Time": wv_layer = process_temporal(wv_layer, dimension["Value"]) # Extract matrix set matrixSet = gc_layer["TileMatrixSetLink"]["TileMatrixSet"] wv_layer["projections"] = { entry["projection"]: { "source": entry["source"], "matrixSet": matrixSet } } # Colormap links if "ows:Metadata" in gc_layer: if "skipPalettes" in config and ident in config["skipPalettes"]: sys.stderr.write("%s: WARNING: Skipping palette for %s\n" % ( prog, ident)) global total_warning_count total_warning_count += 1 else: for item in gc_layer["ows:Metadata"]: if "@xlink:role" not in item: raise KeyError("No xlink:role") schema_version = item["@xlink:role"] if schema_version == "http://earthdata.nasa.gov/gibs/metadata-type/colormap/1.3": colormap_link = item["@xlink:href"] colormap_file = os.path.basename(colormap_link) colormap_id = os.path.splitext(colormap_file)[0] wv_layer["palette"] = { "id": colormap_id }
matrix_set = projection["matrixSet"] if source not in wv["sources"]: error("[%s:%s] Invalid source: %s" % (layer_id, proj_id, source)) del layer["projections"][proj_id] elif "matrixSets" not in wv["sources"][source]: error("[%s:%s] No matrix sets for projection" % (layer_id, proj_id)) del layer["projections"][proj_id] elif matrix_set not in wv["sources"][source]["matrixSets"]: error("[%s:%s] Invalid matrix set: %s" % (layer_id, proj_id, matrix_set)) del layer["projections"][proj_id] if "temporal" in layer: warn("[%s] GC Layer temporal values overwritten by Options" % layer_id) layer = process_temporal(layer, layer["temporal"]) if layer.get("futureTime"): if "endDate" in layer: del layer["endDate"] if layer.get("inactive", False) or layer.get("futureLayer", False): pass else: if "endDate" in layer: del layer["endDate"] if "startDate" in layer: startTime = layer["startDate"].replace('T', ' ').replace('Z', '') if isDateTimeFormat(startTime): d = datetime.strptime(startTime, "%Y-%m-%d %H:%M:%S") else: d = datetime.strptime(layer["startDate"], "%Y-%m-%d") start_date = min(start_date, d)
def process_layer(gc_layer, wv_layers): ident = gc_layer["ows:Identifier"] if ident in skip: print("%s: skipping" % ident) raise SkipException(ident) wv_layers[ident] = {} wv_layer = wv_layers[ident] wv_layer["id"] = ident wv_layer["type"] = "wmts" wv_layer["format"] = gc_layer["Format"] # Extract start and end dates if "Dimension" in gc_layer: dimension = gc_layer["Dimension"] if dimension["ows:Identifier"] == "Time": wv_layer = process_temporal(wv_layer, dimension["Value"]) # Extract matrix set matrixSetLink = gc_layer["TileMatrixSetLink"] matrixSet = matrixSetLink["TileMatrixSet"] wv_layer["projections"] = { entry["projection"]: { "source": entry["source"], "matrixSet": matrixSet, } } if "TileMatrixSetLimits" in matrixSetLink and matrixSetLink[ "TileMatrixSetLimits"] is not None: matrixSetLimits = matrixSetLink["TileMatrixSetLimits"][ "TileMatrixLimits"] mappedSetLimits = [] for setLimit in matrixSetLimits: mappedSetLimits.append({ "tileMatrix": setLimit["TileMatrix"], "minTileRow": int(setLimit["MinTileRow"]), "maxTileRow": int(setLimit["MaxTileRow"]), "minTileCol": int(setLimit["MinTileCol"]), "maxTileCol": int(setLimit["MaxTileCol"]), }) wv_layer["projections"][ entry["projection"]]["matrixSetLimits"] = mappedSetLimits # Vector data links if "ows:Metadata" in gc_layer and gc_layer["ows:Metadata"] is not None: for item in gc_layer["ows:Metadata"]: if "@xlink:role" not in item: raise KeyError("No xlink:role") schema_version = item["@xlink:role"] if schema_version == "http://earthdata.nasa.gov/gibs/metadata-type/layer/1.0": vector_data_link = item["@xlink:href"] vector_data_file = os.path.basename(vector_data_link) vector_data_id = os.path.splitext(vector_data_file)[0] wv_layer["vectorData"] = {"id": vector_data_id} # Colormap links if "ows:Metadata" in gc_layer and gc_layer["ows:Metadata"] is not None: if "skipPalettes" in config and ident in config["skipPalettes"]: sys.stderr.write("%s: WARNING: Skipping palette for %s\n" % (prog, ident)) global total_warning_count total_warning_count += 1 else: for item in gc_layer["ows:Metadata"]: if "@xlink:role" not in item: raise KeyError("No xlink:role") schema_version = item["@xlink:role"] if schema_version == "http://earthdata.nasa.gov/gibs/metadata-type/colormap/1.3": colormap_link = item["@xlink:href"] colormap_file = os.path.basename(colormap_link) colormap_id = os.path.splitext(colormap_file)[0] wv_layer["palette"] = {"id": colormap_id} elif schema_version == "http://earthdata.nasa.gov/gibs/metadata-type/mapbox-gl-style/1.0": vectorstyle_link = item["@xlink:href"] vectorstyle_file = os.path.basename(vectorstyle_link) vectorstyle_id = os.path.splitext(vectorstyle_file)[0] wv_layer["vectorStyle"] = {"id": vectorstyle_id}
matrix_set = projection["matrixSet"] if source not in wv["sources"]: error("[%s:%s] Invalid source: %s" % (layer_id, proj_id, source)) del layer["projections"][proj_id] elif "matrixSets" not in wv["sources"][source]: error("[%s:%s] No matrix sets for projection" % (layer_id, proj_id)) del layer["projections"][proj_id] elif matrix_set not in wv["sources"][source]["matrixSets"]: error("[%s:%s] Invalid matrix set: %s" % (layer_id, proj_id, matrix_set)) del layer["projections"][proj_id] if "temporal" in layer: warn("[%s] GC Layer temporal values overwritten by Options" % layer_id) layer = process_temporal(layer, layer["temporal"]) if layer.get("inactive", False): pass else: if "endDate" in layer: del layer["endDate"] if "startDate" in layer: startTime = layer["startDate"].replace('T', ' ').replace('Z', '') if isDateTimeFormat(startTime): d = datetime.strptime(startTime, "%Y-%m-%d %H:%M:%S") else: d = datetime.strptime(layer["startDate"], "%Y-%m-%d") start_date = min(start_date, d) if start_date != datetime.max: wv["startDate"] = start_date.strftime("%Y-%m-%d") + "T" + start_date.strftime("%H:%M:%S") + "Z";