Exemple #1
0
def xml_encode_coverage_descriptions(
        coverage_descriptions: List[CoverageDescription], **kwargs):
    root = WCS(
        'CoverageDescriptions',
        *[
            WCS(
                'CoverageDescription',
                encode_envelope(coverage_description.grid),
                # TODO: metadata
                encode_domain_set(coverage_description.grid),
                encode_range_type(coverage_description.range_type),
                WCS(
                    'ServiceParameters',
                    WCS('CoverageSubtype',
                        coverage_description.coverage_subtype),
                    WCS('CoverageSubtype',
                        coverage_description.coverage_subtype_parent)
                    if coverage_description.coverage_subtype_parent else None,
                    WCS('nativeFormat', coverage_description.native_format),
                ),
                **{ns_gml('id'): coverage_description.identifier})
            for coverage_description in coverage_descriptions
        ])

    return Result.from_etree(root, **kwargs)
Exemple #2
0
def kvp_encode_get_map_request(request: GetMapRequest, swap_coordinates=False):
    bbox = request.bounding_box.bbox
    if swap_coordinates:
        bbox = [bbox[1], bbox[0], bbox[3], bbox[2]]

    params = [
        ('service', 'WMS'),
        ('version', str(request)),
        ('request', 'GetMap'),
        ('layers', ','.join(request.layers)),
        ('styles', ','.join(request.styles)),
        ('crs', request.bounding_box.crs),
        ('bbox', ','.join(str(v) for v in bbox)),
        ('width', str(request.width)),
        ('height', str(request.height)),
        ('format', request.format),
    ]

    if request.transparent is not None:
        params.append(('transparent', str(request.transparent).upper()))
    if request.background_color is not None:
        params.append(('bgcolor', request.background_color))
    if request.exceptions is not None:
        params.append(('exceptions', request.exceptions))

    for name, value in request.dimensions.items():
        lower = name.lower()
        if lower in ('time', 'elevation'):
            params.append((lower, value))
        else:
            params.append((f'dim_{lower}', value))

    return Result.from_kvp(params)
Exemple #3
0
def xml_encode_get_result(request: GetResultRequest, **kwargs):
    root = WPS(
        'GetResult',
        WPS('JobID', request.job_id),
        service='WPS',
        version=str(request.version),
    )
    return Result.from_etree(root, **kwargs)
Exemple #4
0
def kvp_encode_describe_process(request: DescribeProcessRequest, **kwargs):
    return Result.from_kvp(
        dict(
            service='WCS',
            version=str(request.version),
            request='DescribeProcess',
            processid=','.join(request.process_ids),
        ), **kwargs)
Exemple #5
0
def xml_encode_describe_process(request: DescribeProcessRequest, **kwargs):
    root = WPS(
        'DescribeProcess',
        *[OWS('Identifier', identifier) for identifier in request.process_ids],
        service='WPS',
        version=str(request.version),
    )
    return Result.from_etree(root, **kwargs)
Exemple #6
0
def xml_encode_process_offerings(
        process_descriptions: List[ProcessDescription], **kwargs):
    root = WPS(
        'ProcessOfferings', *[
            WPS('ProcessOffering', encode_process(process_description))
            for process_description in process_descriptions
        ])
    return Result.from_etree(root, **kwargs)
Exemple #7
0
def xml_encode_dismiss(request: DismissRequest, **kwargs):
    root = WPS(
        'Dismiss',
        WPS('JobID', request.job_id),
        service='WPS',
        version=str(request.version),
    )
    return Result.from_etree(root, **kwargs)
Exemple #8
0
def kvp_encode_describe_coverage(request: DescribeCoverageRequest, **kwargs):
    return Result.from_kvp(
        dict(
            service='WCS',
            version=str(request.version),
            request='DescribeCoverage',
            coverageid=','.join(request.coverage_ids),
        ), **kwargs)
Exemple #9
0
def kvp_encode_dismiss(request: DismissRequest, **kwargs):
    return Result.from_kvp(
        dict(
            service='WCS',
            version=str(request.version),
            request='Dismiss',
            jobid=request.job_id,
        ), **kwargs)
Exemple #10
0
def kvp_encode_get_result(request: GetResultRequest, **kwargs):
    return Result.from_kvp(
        dict(
            service='WCS',
            version=str(request.version),
            request='GetResult',
            jobid=request.job_id,
        ), **kwargs)
Exemple #11
0
def xml_encode_describe_coverage(request: DescribeCoverageRequest, **kwargs):
    root = WCS(
        'DescribeCoverage',
        *[
            WCS('CoverageId', identifier)
            for identifier in request.coverage_ids
        ],
        service='WCS',
        version=str(request.version),
    )
    return Result.from_etree(root, **kwargs)
Exemple #12
0
def xml_encode_execute(request: ExecuteRequest, **kwargs):
    root = WPS(
        'Execute',
        OWS('Identifier', request.process_id),
        *[encode_input(input_) for input_ in request.inputs] +
        [encode_output(output) for output in request.output_definitions],
        response=request.response.value,
        mode=request.mode.value,
        service='WPS',
        version=str(request.version),
    )
    return Result.from_etree(root, **kwargs)
Exemple #13
0
def xml_encode_status_info(status_info: StatusInfo, **kwargs):
    root = WPS(
        'StatusInfo',
        WPS('JobID', status_info.job_id),
        WPS('Status', str(status_info.status)),
        WPS('ExpirationDate', isoformat(status_info.expiration_date))
        if status_info.expiration_date else None,
        WPS('EstimatedCompletion', isoformat(status_info.estimated_completion))
        if status_info.estimated_completion else None,
        WPS('NextPoll', isoformat(status_info.next_poll))
        if status_info.next_poll else None,
        WPS('PercentCompleted', str(status_info.percent_completed))
        if status_info.percent_completed else None,
    )
    return Result.from_etree(root, **kwargs)
Exemple #14
0
def xml_encode_capabilities(capabilities: ServiceCapabilities,
                            include_service_identification=True,
                            include_service_provider=True,
                            include_operations_metadata=True,
                            include_service_metadata=True,
                            include_coverage_summary=True,
                            include_dataset_series_summary=True,
                            **kwargs):
    sections = []
    if include_service_identification:
        sections.append(encode_service_identification(capabilities))
    if include_service_provider:
        sections.append(encode_service_provider(capabilities))
    if include_operations_metadata:
        sections.append(encode_operations_metadata(capabilities))
    if include_service_metadata:
        sections.append(encode_service_metadata(capabilities))
    if include_coverage_summary or include_dataset_series_summary:
        contents = WCS('Contents')
        if include_coverage_summary:
            contents.extend(
                encode_coverage_summary(coverage_summary)
                for coverage_summary in capabilities.coverage_summaries)
        if include_dataset_series_summary:
            contents.append(
                WCS(
                    'Extension', *[
                        encode_dataset_series_summary(dataset_series_summary)
                        for dataset_series_summary in
                        capabilities.dataset_series_summaries
                    ]))
        sections.append(contents)

    root = WCS('Capabilities',
               *sections,
               version="2.0.1",
               updateSequence=capabilities.update_sequence)

    return Result.from_etree(root, **kwargs)
Exemple #15
0
def xml_encode_capabilities(capabilities: ServiceCapabilities,
                            include_service_identification=True,
                            include_service_provider=True,
                            include_operations_metadata=True,
                            include_contents=True,
                            **kwargs):

    sections = []
    if include_service_identification:
        sections.append(encode_service_identification(capabilities))
    if include_service_provider:
        sections.append(encode_service_provider(capabilities))
    if include_operations_metadata:
        sections.append(encode_operations_metadata(capabilities))
    if include_contents:
        sections.append(encode_contents(capabilities))

    root = WPS('Capabilities',
               *sections,
               version="2.0.1",
               updateSequence=capabilities.update_sequence)

    return Result.from_etree(root, **kwargs)
Exemple #16
0
def xml_encode_capabilities(capabilities: ServiceCapabilities, **kwargs):
    root = WMS(
        'WMS_Capabilities',
        WMS(
            'Service',
            WMS('Name', 'WMS'),
            WMS('Title', capabilities.title or ''),
            WMS('Abstract', capabilities.abstract),
            WMS(
                'KeywordList', *
                [WMS('Keyword', keyword) for keyword in capabilities.keywords])
            if capabilities.keywords else None,
            WMS('OnlineResource',
                **{**reference_attrs(href=capabilities.online_resource)}),
            WMS(
                'ContactInformation',
                WMS('ContactPerson', capabilities.individual_name)
                if capabilities.individual_name else None,
                WMS('ContactOrganization', capabilities.organisation_name)
                if capabilities.organisation_name else None,
                WMS('ContactPosition', capabilities.position_name)
                if capabilities.position_name else None,
                WMS(
                    'ContactAddress',
                    WMS('AddressType', ''),
                    WMS('Address', capabilities.delivery_point or ''),
                    WMS('City', capabilities.city or ''),
                    WMS('StateOrProvince', capabilities.administrative_area
                        or ''),
                    WMS('PostCode', capabilities.postal_code or ''),
                    WMS('Country', capabilities.country or ''),
                ) if capabilities.delivery_point else None,
                WMS('ContactVoiceTelephone', capabilities.phone_voice)
                if capabilities.phone_voice else None,
                WMS('ContactFacsimileTelephone', capabilities.phone_facsimile)
                if capabilities.phone_facsimile else None,
                WMS('ContactElectronicMailAddress',
                    capabilities.electronic_mail_address)
                if capabilities.electronic_mail_address else None,
            ),
            WMS('Fees', capabilities.fees) if capabilities.fees else None,
            WMS('AccessConstraints', capabilities.access_constraints[0])
            if capabilities.access_constraints else None,
            WMS('LayerLimit', str(capabilities.layer_limit))
            if capabilities.layer_limit is not None else None,
            WMS('MaxWidth', str(capabilities.max_width))
            if capabilities.max_width is not None else None,
            WMS('MaxHeight', str(capabilities.max_height))
            if capabilities.max_height is not None else None,
        ),
        WMS(
            'Capability',
            WMS(
                'Request', *[
                    encode_operation(operation)
                    for operation in capabilities.operations
                ]),
            WMS(
                'Exception', *[
                    WMS('Format', exception_format)
                    for exception_format in capabilities.exception_formats
                ]),
            encode_layer(capabilities.layer) if capabilities.layer else None,
        ),
        version=(str(capabilities.service_type_versions[0])
                 if capabilities.service_type_versions else '1.3.0'),
        updateSequence=capabilities.update_sequence)

    return Result.from_etree(root, **kwargs)
Exemple #17
0
def kvp_encode_get_coverage(request: GetCoverageRequest):
    params = [
        ('service', 'WCS'),
        ('version', str(request.version)),
        ('request', 'GetCoverage'),
        ('coverageid', request.coverage_id),
    ]

    for subset in request.subsets:
        if isinstance(subset, Trim):
            low = maybe_quote(subset.low) if subset.low is not None else '*'
            high = maybe_quote(subset.high) if subset.high is not None else '*'
            params.append(('subset', f'{subset.dimension}({low},{high})'))
        elif isinstance(subset, Slice):
            params.append(
                ('subset', f'{subset.dimension}({maybe_quote(subset.point)})'))

    if request.format is not None:
        params.append(('format', request.format))

    if request.mediatype is not None:
        params.append(('mediaType', request.mediatype))

    if request.subsetting_crs is not None:
        params.append(('subsettingCrs', request.subsetting_crs))

    if request.output_crs is not None:
        params.append(('outputCrs', request.output_crs))

    scale_sizes = [
        scale for scale in request.scales if isinstance(scale, ScaleSize)
    ]
    scale_axes = [
        scale for scale in request.scales if isinstance(scale, ScaleAxis)
    ]
    scale_extents = [
        scale for scale in request.scales if isinstance(scale, ScaleExtent)
    ]

    if request.scalefactor:
        params.append(('scaleFactor', str(request.scalefactor)))
    if scale_sizes:
        params.append(('scaleSize', ','.join(f'{scale.axis}({scale.size})'
                                             for scale in scale_sizes)))
    if scale_axes:
        params.append(('scaleAxes', ','.join(f'{scale.axis}({scale.factor})'
                                             for scale in scale_axes)))
    if scale_extents:
        params.append(
            ('scaleExtent', ','.join(f'{scale.axis}({scale.low}:{scale.high})'
                                     for scale in scale_extents)))

    if request.interpolation or request.axis_interpolations:
        if request.interpolation:
            params.append(('interpolation', request.interpolation))
        for axis_interpolation in request.axis_interpolations:
            axis = axis_interpolation.axis
            method = axis_interpolation.method
            params.append(('interpolationPerAxis', f'{axis},{method}'))

    geotiff = request.geotiff_encoding_parameters
    if geotiff:
        if geotiff.compression is not None:
            params.append(('geotiff:compression', geotiff.compression))
        if geotiff.jpeg_quality:
            params.append(('geotiff:jpeg_quality', geotiff.jpeg_quality))

        if geotiff.predictor is not None:
            params.append(('geotiff:predictor', geotiff.predictor))

        if geotiff.interleave is not None:
            params.append(('geotiff:interleave', geotiff.interleave))

        if geotiff.tiling is not None:
            params.append(('geotiff:tiling', str(geotiff.tiling).lower()))

        if geotiff.tile_width is not None:
            params.append(('geotiff:tilewidth', str(geotiff.tile_width)))

        if geotiff.tile_height is not None:
            params.append(('geotiff:tileheight', str(geotiff.tile_height)))

    return Result.from_kvp(params)
Exemple #18
0
def xml_encode_get_coverage(request: GetCoverageRequest, **kwargs):
    root = WCS(
        'GetCoverage',
        WCS('CoverageId', request.coverage_id),
        service='WCS',
        version=str(request.version),
    )

    for subset in request.subsets:
        if isinstance(subset, Trim):
            node = WCS('DimensionTrim', WCS('Dimension', subset.dimension))
            if subset.low is not None:
                node.append(WCS('TrimLow', str(subset.low)))
            if subset.high is not None:
                node.append(WCS('TrimHigh', str(subset.high)))
            root.append(node)
        elif isinstance(subset, Slice):
            root.append(
                WCS('DimensionSlice', WCS('Dimension', subset.dimension),
                    WCS('SlicePoint', str(subset.point))))

    if request.format is not None:
        root.append(WCS('format', request.format))

    if request.mediatype is not None:
        root.append(WCS('mediaType', request.mediatype))

    extension_node = WCS('Extension')

    if request.subsetting_crs is not None:
        extension_node.append(CRS('subsettingCrs', request.subsetting_crs))

    if request.output_crs is not None:
        extension_node.append(CRS('outputCrs', request.output_crs))

    scale_sizes = [
        scale for scale in request.scales if isinstance(scale, ScaleSize)
    ]
    scale_axes = [
        scale for scale in request.scales if isinstance(scale, ScaleAxis)
    ]
    scale_extents = [
        scale for scale in request.scales if isinstance(scale, ScaleExtent)
    ]

    if request.scalefactor:
        extension_node.append(
            SCAL('ScaleByFactor', SCAL('scaleFactor',
                                       str(request.scalefactor))))
    if scale_sizes:
        extension_node.append(
            SCAL(
                'ScaleToSize', *[
                    SCAL('TargetAxisSize', SCAL('axis', scale.axis),
                         SCAL('targetSize', str(scale.size)))
                    for scale in scale_sizes
                ]))
    if scale_axes:
        extension_node.append(
            SCAL(
                'ScaleAxesByFactor', *[
                    SCAL('ScaleAxis', SCAL('axis', scale.axis),
                         SCAL('scaleFactor', str(scale.factor)))
                    for scale in scale_axes
                ]))
    if scale_extents:
        extension_node.append(
            SCAL(
                'ScaleToExtent', *[
                    SCAL('TargetAxisExtent', SCAL('axis', scale.axis),
                         SCAL('low', str(scale.low)),
                         SCAL('high', str(scale.high)))
                    for scale in scale_extents
                ]))

    if request.interpolation or request.axis_interpolations:
        node = INT('Interpolation')
        if request.interpolation:
            node.append(INT('globalInterpolation', request.interpolation))
        for axis_interpolation in request.axis_interpolations:
            node.append(
                INT(
                    'InterpolationPerAxis',
                    INT('axis', axis_interpolation.axis),
                    INT('interpolationMethod', axis_interpolation.method),
                ))
        extension_node.append(node)

    geotiff = request.geotiff_encoding_parameters
    if geotiff:
        geotiff_node = GEOTIFF('parameters')
        if geotiff.compression is not None:
            geotiff_node.append(GEOTIFF('compression', geotiff.compression))
        if geotiff.jpeg_quality:
            geotiff_node.append(GEOTIFF('jpeg_quality', geotiff.jpeg_quality))

        if geotiff.predictor is not None:
            geotiff_node.append(GEOTIFF('predictor', geotiff.predictor))

        if geotiff.interleave is not None:
            geotiff_node.append(GEOTIFF('interleave', geotiff.interleave))

        if geotiff.tiling is not None:
            geotiff_node.append(GEOTIFF('tiling', str(geotiff.tiling).lower()))

        if geotiff.tile_width is not None:
            geotiff_node.append(GEOTIFF('tilewidth', str(geotiff.tile_width)))

        if geotiff.tile_height is not None:
            geotiff_node.append(GEOTIFF('tileheight',
                                        str(geotiff.tile_height)))

        if len(geotiff_node):
            extension_node.append(geotiff_node)

    if len(extension_node):
        root.append(extension_node)

    return Result.from_etree(root, **kwargs)