Esempio n. 1
0
def build_figure(requestParams, sessionEndpointData=None):
    """Generates a figure image for a set of layers defined though request parameters.
    @param requestParams: HTTP request parameters
    @param sessionEndpointData: data defining endpoints added during session
    """
    figureOptions = figure_parameters.FigureOptions(requestParams)
    commonLayerParams = figure_parameters.makeDefaultedParameters(requestParams, {})
    layerInfoBuilder = LayerInfoBuilder(requestParams, commonLayerParams)
    layerInfoList = layerInfoBuilder.buildInfo(sessionEndpointData)
    if len(layerInfoList) == 0:
        raise Exception("There are no layers to draw in the figure.")

    return buildFigureForLayers(requestParams, figureOptions, commonLayerParams, layerInfoList, None)
Esempio n. 2
0
def make_export(params, applicationUrl, configuration, sessionEndpointData):
    """Generates an export of a type depending on the request parameters. Depending on whether
    multiple dimension values are specified, the result may be an animation or a static map.
    """
    # Process the parameters for the specified layers.
    figureOptions = figure_parameters.FigureOptions(params)
    commonLayerParams = figure_parameters.makeDefaultedParameters(params, {'WIDTH': 800, 'HEIGHT': 400})

    protocol = 'WCS' if params['animation-format'] == 'WCS' else 'WMS'
    layerInfoBuilder = LayerInfoBuilder(params, commonLayerParams, protocol)
    layerInfoList = layerInfoBuilder.buildInfo(sessionEndpointData)
    if len(layerInfoList) == 0:
        return ExportResult(False, errorMessage = "There are no layers to export.")

    exportParams = ExportParameters(params, figureOptions, commonLayerParams, layerInfoList, applicationUrl, configuration)

    # Check that the limit on the number of steps is not exceeded.

    # If there is a dimension to animate over, find the dimension values within the specified range.
    if exportParams.isAnimation():
        # Retrieve the WMC data for the layer.
        layerInfo = layerInfoList[exportParams.animationLayerNumber - 1]
        layerData = layerInfo.wmsLayer
        if layerData == None:
            return ExportResult(False, errorMessage = "Information about requested layers no longer held. Please refresh your browser.")

        # Find the set of dimension values corresponding to the specified name.
        dimension = None
        for dim in layerData.dimensions:
            if dim['name'].upper() == exportParams.animationDimension:
                dimension = dim
                break
        if dimension == None:
            return ExportResult(False, errorMessage = "Information about requested layers no longer held. Please refresh your browser.")

        # Find the values for the dimension that is to vary in the animation within the required range.
        try:
            dimValueSet = findDimensionRange(dimension['dimensionValues'], exportParams.startValue,
                                             exportParams.endValue, exportParams.numberSteps)
        except ValueError, exc:
            return ExportResult(False, errorMessage = exc.__str__())

        exportParams.setDimensionValues(dimValueSet)