Пример #1
0
def test_complex_output_href():
    """ Test external reference in complex output 
    """

    kwargs = {
        'identifier': 'hreftest',
        'title': '',
        'abstract': '',
    }

    output = ComplexOutput(supported_formats=[
        Format("application/x-ogc-wms"),
        Format("application/x-ogc-wfs")
    ],
                           as_reference=True,
                           **kwargs)

    output.output_format = "application/x-ogc-wms"
    output.url = "http://my.org/external/ref"

    output_elements = output.execute_xml()

    # Check that <wps:Reference href=...> is not namspaced
    element = output_elements.xpath(
        '//wps:Reference',
        namespaces={'wps': "http://www.opengis.net/wps/1.0.0"})

    assert len(element) == 1
    assert 'href' in element[0].attrib
Пример #2
0
def parse_layer_output(outdef: QgsProcessingOutputDefinition,
                       kwargs) -> ComplexOutput:
    """ Parse layer output

        A layer output is merged to a qgis project, we return
        the wms uri associated to the project
    """
    if isinstance(outdef, OUTPUT_LAYER_TYPES):
        if isinstance(outdef, QgsProcessingOutputVectorLayer):
            return ComplexOutput(supported_formats=[
                Format("application/x-ogc-wms"),
                Format("application/x-ogc-wfs")
            ],
                                 as_reference=True,
                                 **kwargs)
        elif isinstance(outdef, QgsProcessingOutputRasterLayer):
            return ComplexOutput(supported_formats=[
                Format("application/x-ogc-wms"),
                Format("application/x-ogc-wcs")
            ],
                                 as_reference=True,
                                 **kwargs)
        else:
            return ComplexOutput(
                supported_formats=[Format("application/x-ogc-wms")],
                as_reference=True,
                **kwargs)
Пример #3
0
def parse_file_output( outdef: QgsProcessingOutputDefinition, kwargs, 
                       alg: QgsProcessingAlgorithm=None ) -> ComplexOutput:
    """ Parse file output definition

        QgsProcessingOutputDefinition metadata will be checked to get 
        wps parameter settings:

            - 'wps:as_reference': boolean, True if the file will be sent as reference. If
            false, the file will included in the body of the response. Default is True.
    """
    as_reference = confservice.getboolean('server','outputfile_as_reference')
    if isinstance(outdef, QgsProcessingOutputHtml):
        mime = mimetypes.types_map.get('.html')
        return ComplexOutput(supported_formats=[Format(mime)],**kwargs)
    elif isinstance(outdef, QgsProcessingOutputFile):
        # Try to get a corresponding inputFileDefinition
        # See https://qgis.org/pyqgis/master/core/QgsProcessingParameterFileDestination.html
        mime = None
        if alg:
            inputdef = alg.parameterDefinition(outdef.name())
            if isinstance(inputdef, QgsProcessingParameterFileDestination):
                mime = mimetypes.types_map.get("."+inputdef.defaultFileExtension())
                as_reference = inputdef.metadata().get('wps:as_reference',as_reference)
        if mime is None:
            LOGGER.warning("Cannot set file type for output %s", outdef.name())
            mime = "application/octet-stream"
        return ComplexOutput(supported_formats=[Format(mime)], as_reference=as_reference, **kwargs)
Пример #4
0
def to_output_file(file_name: str, out: ComplexOutput,
                   context: ProcessingContext) -> ComplexOutput:
    """ Output file
    """
    if out.as_reference:
        out.url = context.store_url.format(file=file_name)
    else:
        out.file = os.path.join(context.workdir, file_name)
    return out
Пример #5
0
def parse_file_output(outdef: QgsProcessingOutputDefinition,
                      kwargs,
                      alg: QgsProcessingAlgorithm = None) -> ComplexOutput:
    """ Parse file output definition
    """
    if isinstance(outdef, QgsProcessingOutputHtml):
        mime = mimetypes.types_map.get('.html')
        return ComplexOutput(supported_formats=[Format(mime)], **kwargs)
    elif isinstance(outdef, QgsProcessingOutputFile):
        # Try to get a corresponding inputFileDefinition
        mime = None
        if alg:
            inputdef = alg.parameterDefinition(outdef.name())
            if isinstance(inputdef, QgsProcessingParameterFileDestination):
                mime = mimetypes.types_map.get("." +
                                               inputdef.defaultFileExtension())
        if mime is None:
            LOGGER.warning("Cannot set file type for output %s", outdef.name())
            mime = "application/octet-stream"
        return ComplexOutput(supported_formats=[Format(mime)], **kwargs)
Пример #6
0
def create_complex_process():
    frmt = Format(mime_type='application/gml')  # this is unknown mimetype

    return WPSProcess(handler=complex_process,
                      identifier='my_complex_process',
                      title='Complex process',
                      inputs=[
                          ComplexInput('complex',
                                       'Complex input',
                                       supported_formats=[frmt])
                      ],
                      outputs=[
                          ComplexOutput('complex',
                                        'Complex output',
                                        supported_formats=[frmt])
                      ])