def download(self): params = self._getParams() log.debug("params = %s" % (params,)) endpoint = params.get("ENDPOINT") args = {} args["identifier"] = params["LAYER"] args["bbox"] = tuple(params.get("BBOX").split(",")) args["format"] = params["FORMAT"] args["crs"] = params["CRS"] if params.get("SINGLE_TIME", "").upper() == "TRUE": args["time"] = [params.get("TIME")] else: args["time"] = [params.get("TIME"), params.get("TIME_END")] wcs, layers = self._getWCSObj(endpoint) log.debug("wcs.url = %s" % (wcs.url,)) assert args["identifier"] in layers log.debug("args = %s" % (args,)) oldProxy = proxyFix(endpoint) try: output = wcs.getCoverage(**args) except Exception, e: log.exception("Exception occurred") raise
def _getWCSMetadata(self, wcs, layer): oldProxy = proxyFix(wcs.url) try: layerMetadata = wcs[layer] bboxLimits = ",".join([str(x) for x in layerMetadata.boundingBoxWGS84]) timepositions = layerMetadata.timepositions supportedFormats = layerMetadata.supportedFormats supportedCRS = layerMetadata.supportedCRS finally: resetProxy(oldProxy) return layerMetadata, bboxLimits, timepositions, supportedFormats, supportedCRS
def _getWcsData(params): """Performs WCS retrieval for a set of parameters. @param params: parameters to use in WCS r equest @return tuple (WCS response data, content header information) """ params = _getParams(params) log.debug("params = %s" % (params,)) endpoint = params.get("ENDPOINT") # Set OWSlib WCS parameters. args = {} layerId = params["LAYERS"].partition(",")[0] args["identifier"] = layerId # Get the bounding box values (W, S, E, N). args["bbox"] = tuple(params.get("BBOX").split(",")) args["format"] = params["FORMAT"] args["crs"] = params["CRS"] args["time"] = params.get("TIME") wcs, layers = _getWCSObj(endpoint) log.debug("wcs.url = %s" % (wcs.url,)) if layerId not in layers: raise Exception("Layer %s is not available for WCS download" % layerId) # Find the dimension names for the layer, and if there are any request parameters with the same # name as a dimension, use them as a GetCoverage argument. layer = [x for x in wcs.items() if x[0] == layerId][0][1] for dimensionName in [a.name.upper() for a in layer.axisDescriptions]: log.debug("Checking for value for dimension %s" % dimensionName) if dimensionName in params: args[dimensionName] = params[dimensionName] log.debug("Found value %s" % params[dimensionName]) log.debug("args = %s" % (args,)) # Perform the GetCoverage request. oldProxy = proxyFix(endpoint) try: output = wcs.getCoverage(**args) except Exception, e: log.exception("Exception occurred") raise
def _getWCSObj(self, endpoint): oldProxy = proxyFix(endpoint) try: log.debug("wcs endpoint = %s" % (endpoint,)) getCapabilitiesEndpoint = parseEndpointString(endpoint, {"Service": "WCS", "Request": "GetCapabilities"}) log.debug("wcs endpoint = %s" % (getCapabilitiesEndpoint,)) # requires OWSLib with cookie support wcs = WebCoverageService( getCapabilitiesEndpoint, version="1.0.0", cookies=request.headers.get("Cookie", "") ) layers = [x[0] for x in wcs.items()] finally: resetProxy(oldProxy) return wcs, layers