Beispiel #1
0
#-------------------------------------------------------------------------------
# Copyright (C) 2013 EOX IT Services GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from eoxserver.core.util.xmltools import NameSpace, NameSpaceMap

ns_xlink = NameSpace("http://www.w3.org/1999/xlink", "xlink")
ns_ogc = NameSpace("http://www.opengis.net/ogc", "ogc")
ns_ows = NameSpace("http://www.opengis.net/ows/1.1", "ows")
ns_wcs = NameSpace("http://www.opengis.net/wcs/1.1", "wcs")

nsmap = NameSpaceMap(ns_xlink, ns_ogc, ns_ows, ns_wcs)
Beispiel #2
0
            inline with the :meth:`create_fields` method.
        """
        feature.SetGeometry(
            ogr.CreateGeometryFromWkb(str(eo_object.footprint.wkb)))
        feature.SetField("id", eo_object.identifier.encode("utf-8"))
        feature.SetField("begin_time", isoformat(eo_object.begin_time))
        feature.SetField("end_time", isoformat(eo_object.end_time))

    def cleanup(self, driver, datasource, filename):
        """ Perform any necessary cleanup steps, like removing the temporary
            file.
        """
        driver.DeleteDataSource(filename)


ns_atom = NameSpace("http://www.w3.org/2005/Atom", "atom")
ns_opensearch = NameSpace("http://a9.com/-/spec/opensearch/1.1/", "opensearch")
ns_dc = NameSpace("http://purl.org/dc/elements/1.1/", "dc")
ns_georss = NameSpace("http://www.georss.org/georss", "georss")
ns_media = NameSpace("http://search.yahoo.com/mrss/", "media")
ns_owc = NameSpace("http://www.opengis.net/owc/1.0", "owc")

nsmap = NameSpaceMap(ns_atom, ns_dc, ns_georss, ns_media, ns_owc)

ATOM = ElementMaker(namespace=ns_atom.uri)
OS = ElementMaker(namespace=ns_opensearch.uri)
DC = ElementMaker(namespace=ns_dc.uri, nsmap=nsmap)
GEORSS = ElementMaker(namespace=ns_georss.uri, nsmap=nsmap)
MEDIA = ElementMaker(namespace=ns_media.uri, nsmap=nsmap)
OWC = ElementMaker(namespace=ns_owc.uri, nsmap=nsmap)
Beispiel #3
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from lxml.builder import ElementMaker
from lxml.etree import ProcessingInstruction, ElementTree
from django.conf import settings
from eoxserver.core.util.xmltools import XMLEncoder, NameSpace, NameSpaceMap


ns_xlink = NameSpace("http://www.w3.org/1999/xlink", "xlink")
ns_ows = NameSpace("http://www.opengis.net/ows/1.1", "ows", "http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd")
ns_xml = NameSpace("http://www.w3.org/XML/1998/namespace", "xml")

nsmap = NameSpaceMap(ns_ows)
OWS = ElementMaker(namespace=ns_ows.uri, nsmap=nsmap)


class OWS11ExceptionXMLEncoder(XMLEncoder):
    def encode_exception(self, message, version, code, locator=None):
        exception_attributes = {
            "exceptionCode": code
        }

        if locator:
            exception_attributes["locator"] = locator
Beispiel #4
0
from django.utils.six import string_types

from eoxserver.core.util.xmltools import NameSpace, NameSpaceMap, ns_xsi
from eoxserver.core.util.timetools import parse_iso8601
from eoxserver.services.subset import Trim, Slice, is_temporal, all_axes
from eoxserver.services.gml.v32.encoders import (ns_gml, ns_gmlcov, ns_om,
                                                 ns_eop, GML, GMLCOV, OM, EOP)
from eoxserver.services.ows.common.v20.encoders import ns_xlink, ns_ows, OWS
from eoxserver.services.exceptions import (
    InvalidSubsettingException, InvalidAxisLabelException,
    NoSuchFieldException, InvalidFieldSequenceException,
    InterpolationMethodNotSupportedException, InvalidScaleFactorException,
    InvalidScaleExtentException, ScaleAxisUndefinedException)

# namespace declarations
ns_ogc = NameSpace("http://www.opengis.net/ogc", "ogc")
ns_wcs = NameSpace("http://www.opengis.net/wcs/2.0", "wcs")
ns_crs = NameSpace("http://www.opengis.net/wcs/crs/1.0", "crs")
ns_rsub = NameSpace("http://www.opengis.net/wcs/range-subsetting/1.0", "rsub")
ns_eowcs = NameSpace("http://www.opengis.net/wcs/wcseo/1.0", "wcseo",
                     "http://schemas.opengis.net/wcs/wcseo/1.0/wcsEOAll.xsd")
ns_swe = NameSpace("http://www.opengis.net/swe/2.0", "swe")
ns_int = NameSpace("http://www.opengis.net/wcs/interpolation/1.0", "int")
ns_scal = NameSpace("http://www.opengis.net/wcs/scaling/1.0", "scal")

# namespace map
nsmap = NameSpaceMap(ns_xlink, ns_ogc, ns_ows, ns_gml, ns_gmlcov, ns_wcs,
                     ns_crs, ns_rsub, ns_eowcs, ns_om, ns_eop, ns_swe, ns_int,
                     ns_scal)

# Element factories
Beispiel #5
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------


from lxml.builder import ElementMaker

from eoxserver.core.util.xmltools import XMLEncoder, NameSpace, NameSpaceMap


ns_xlink = NameSpace("http://www.w3.org/1999/xlink", "xlink")
ns_ows = NameSpace("http://www.opengis.net/ows/2.0", "ows", "http://schemas.opengis.net/ows/2.0/owsAll.xsd")
ns_xml = NameSpace("http://www.w3.org/XML/1998/namespace", "xml")

nsmap = NameSpaceMap(ns_ows)
OWS = ElementMaker(namespace=ns_ows.uri, nsmap=nsmap)


class OWS20Encoder(XMLEncoder):
    def encode_reference(self, node_name, href, reftype="simple"):

        attributes = {ns_xlink("href"): href}
        if reftype:
            attributes[ns_xlink("type")] = reftype

        return OWS(node_name, **attributes)
Beispiel #6
0
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from eoxserver.core.decoders import kvp, xml, upper, typelist
from eoxserver.core.util.xmltools import NameSpace, NameSpaceMap
from eoxserver.services.ows.version import parse_version_string

ns_xlink = NameSpace("http://www.w3.org/1999/xlink", "xlink")
ns_ows10 = NameSpace("http://www.opengis.net/ows/1.0", "ows10")
ns_ows11 = NameSpace("http://www.opengis.net/ows/1.1", "ows11")
ns_ows20 = NameSpace("http://www.opengis.net/ows/2.0", "ows20")

nsmap = NameSpaceMap(ns_ows10, ns_ows11, ns_ows20)


def get_decoder(request):
    """ Convenience function to return the right OWS Common request deocder for
        the given `django.http.HttpRequest`.
    """
    if request.method == "GET":
        return OWSCommonKVPDecoder(request.GET)
    elif request.method == "POST":
        # TODO: this may also be in a different format.
Beispiel #7
0
from django.template.loader import render_to_string
from django.conf import settings

from eoxserver.core.util.xmltools import etree, NameSpace, NameSpaceMap, typemap
from eoxserver.core.util.timetools import isoformat
from eoxserver.resources.coverages import models
from eoxserver.services.opensearch.formats.base import (
    BaseFeedResultFormat, ns_georss, ns_media, ns_owc
)
from eoxserver.services.opensearch.config import (
    DEFAULT_EOXS_OPENSEARCH_SUMMARY_TEMPLATE
)


# namespace declarations
ns_atom = NameSpace("http://www.w3.org/2005/Atom", None)
ns_opensearch = NameSpace("http://a9.com/-/spec/opensearch/1.1/", "opensearch")
ns_gml = NameSpace("http://www.opengis.net/gml", "gml")
ns_dc = NameSpace("http://purl.org/dc/elements/1.1/", "dc")

# namespace map
nsmap = NameSpaceMap(ns_atom, ns_opensearch, ns_dc, ns_georss, ns_media, ns_owc)

# Element factories
ATOM = ElementMaker(namespace=ns_atom.uri, nsmap=nsmap, typemap=typemap)
OS = ElementMaker(namespace=ns_opensearch.uri, nsmap=nsmap)
GML = ElementMaker(namespace=ns_gml.uri, nsmap=nsmap)
DC = ElementMaker(namespace=ns_dc.uri, nsmap=nsmap)


class AtomResultFormat(BaseFeedResultFormat):
Beispiel #8
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from lxml.builder import ElementMaker

from eoxserver.core.util.xmltools import NameSpace, NameSpaceMap
from eoxserver.core.util.timetools import isoformat
from eoxserver.resources.coverages import crss

# namespace declarations
ns_gml = NameSpace("http://www.opengis.net/gml/3.2", "gml")
ns_gmlcov = NameSpace("http://www.opengis.net/gmlcov/1.0", "gmlcov")
ns_om = NameSpace("http://www.opengis.net/om/2.0", "om")
ns_eop = NameSpace("http://www.opengis.net/eop/2.0", "eop")

nsmap = NameSpaceMap(ns_gml, ns_gmlcov, ns_om, ns_eop)

# Element factories
GML = ElementMaker(namespace=ns_gml.uri, nsmap=nsmap)
GMLCOV = ElementMaker(namespace=ns_gmlcov.uri, nsmap=nsmap)
OM = ElementMaker(namespace=ns_om.uri, nsmap=nsmap)
EOP = ElementMaker(namespace=ns_eop.uri, nsmap=nsmap)


class GML32Encoder(object):
    def encode_linear_ring(self, ring, sr):
Beispiel #9
0
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ------------------------------------------------------------------------------

from lxml.builder import ElementMaker

from eoxserver.core.util.xmltools import XMLEncoder, NameSpace, NameSpaceMap

ns_wms = NameSpace("http://www.opengis.net/wms")
ns_xlink = NameSpace("http://www.w3.org/1999/xlink", "xlink")
nsmap = NameSpaceMap(ns_wms, ns_xlink)

WMS = ElementMaker(namespace=ns_wms.uri, nsmap=nsmap)


class WMS13Encoder(XMLEncoder):
    def encode_capabilities(self, config, ows_url, srss, formats, info_formats,
                            layer_descriptions):
        return WMS(
            "WMS_Capabilities",
            WMS(
                "Service",
                WMS("Name", config.name),
                WMS("Title", config.title),
Beispiel #10
0
from itertools import chain

from lxml.etree import CDATA
from lxml.builder import ElementMaker
from django.core.urlresolvers import reverse

from eoxserver.core.util.xmltools import etree, NameSpace, NameSpaceMap, typemap
from eoxserver.core.util.timetools import isoformat
from eoxserver.services.opensearch.formats.base import (BaseFeedResultFormat,
                                                        ns_opensearch, ns_dc,
                                                        ns_atom, ns_media,
                                                        ns_owc)

# namespace declarations
ns_georss = NameSpace("http://www.georss.org/georss", "georss")
ns_gml = NameSpace("http://www.opengis.net/gml", "gml")

# namespace map
nsmap = NameSpaceMap(ns_georss, ns_gml, ns_opensearch, ns_dc, ns_atom,
                     ns_media, ns_owc)

# Element factories
GEORSS = ElementMaker(namespace=ns_georss.uri, nsmap=nsmap)
GML = ElementMaker(namespace=ns_gml.uri, nsmap=nsmap)
RSS = ElementMaker(typemap=typemap)


class RSSResultFormat(BaseFeedResultFormat):
    """ RSS result format.
    """
Beispiel #11
0
        code = getattr(exception, "code", None) or type(exception).__name__

        return (encoder.serialize(
            encoder.encode_exception(str(exception), code,
                                     locator), ), encoder.content_type, 400)


class WMS13Decoder(kvp.Decoder):
    width = kvp.Parameter(type=int, num="?")
    height = kvp.Parameter(type=int, num="?")
    format = kvp.Parameter(num="?")
    bgcolor = kvp.Parameter(num="?")
    exceptions = kvp.Parameter(num="?", type=lower, default="xml")


ns_ogc = NameSpace("http://www.opengis.net/ogc", "ogc")
nsmap = NameSpaceMap(ns_ogc)
OGC = ElementMaker(namespace=ns_ogc.uri, nsmap=nsmap)


class WMS13ExceptionXMLEncoder(XMLEncoder):
    def encode_exception(self, message, code, locator=None):
        attributes = {"code": code}
        if locator:
            attributes["locator"] = locator

        return OGC("ServiceExceptionReport",
                   OGC("ServiceException", str(message), **attributes),
                   version="1.3.0")

    @property
Beispiel #12
0
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from django.contrib.gis.geos import Polygon, MultiPolygon

from eoxserver.core.util.timetools import parse_iso8601
from eoxserver.core.util.xmltools import parse, NameSpace, NameSpaceMap
from eoxserver.core.util.iteratortools import pairwise
from eoxserver.core import Component, implements
from eoxserver.core.decoders import xml
from eoxserver.resources.coverages.metadata.interfaces import (
    MetadataReaderInterface
)


NS_EOP = NameSpace("http://www.opengis.net/eop/2.0", "eop")
NS_OM = NameSpace("http://www.opengis.net/om/2.0", "om")
NS_GML = NameSpace("http://www.opengis.net/gml/3.2", "gml")
nsmap = NameSpaceMap(NS_EOP, NS_OM, NS_GML)


class EOOMFormatReader(Component):
    implements(MetadataReaderInterface)

    def test(self, obj):
        tree = parse(obj)
        return tree is not None and tree.getroot().tag == NS_EOP("EarthObservation")

    def read(self, obj):
        tree = parse(obj)
        if tree is not None:
Beispiel #13
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from django.contrib.gis.geos import Polygon, MultiPolygon

from eoxserver.core.util.timetools import parse_iso8601
from eoxserver.core.util.xmltools import parse, NameSpace, NameSpaceMap
from eoxserver.core.util.iteratortools import pairwise
from eoxserver.core.decoders import xml, to_dict, InvalidParameterException
from eoxserver.core import Component

NS_EOP_20 = NameSpace("http://www.opengis.net/eop/2.0", "eop")
NS_OPT_20 = NameSpace("http://www.opengis.net/opt/2.0", "opt")
NS_SAR_20 = NameSpace("http://www.opengis.net/sar/2.0", "sar")
NS_ATM_20 = NameSpace("http://www.opengis.net/atm/2.0", "atm")

namespaces_20 = [NS_EOP_20, NS_OPT_20, NS_SAR_20, NS_ATM_20]

NS_EOP_21 = NameSpace("http://www.opengis.net/eop/2.1", "eop")
NS_OPT_21 = NameSpace("http://www.opengis.net/opt/2.1", "opt")
NS_SAR_21 = NameSpace("http://www.opengis.net/sar/2.1", "sar")
NS_ATM_21 = NameSpace("http://www.opengis.net/atm/2.1", "atm")

namespaces_21 = [NS_EOP_21, NS_OPT_21, NS_SAR_21, NS_ATM_21]

NS_OM = NameSpace("http://www.opengis.net/om/2.0", "om")
NS_GML = NameSpace("http://www.opengis.net/gml/3.2", "gml")
Beispiel #14
0
class GeoExtension(Component):
    """ Implementation of the OpenSearch `'Geo' extension draft
    <http://www.opensearch.org/Specifications/OpenSearch/Extensions/Geo/1.0/Draft_2>`_.
    Currently all parameters apart from the ``name`` are supported. The point
    plus radius with the relation type ``contains`` requires a PostGIS database
    backend.
    """
    implements(SearchExtensionInterface)

    namespace = NameSpace(
        "http://a9.com/-/opensearch/extensions/geo/1.0/", "geo"
    )

    def filter(self, qs, parameters):
        decoder = GeoExtensionDecoder(parameters)

        geom = decoder.box or decoder.geometry
        lon, lat = decoder.lon, decoder.lat
        distance = decoder.radius
        relation = decoder.relation
        uid = decoder.uid

        if geom:
            if relation == "intersects":
                qs = qs.filter(footprint__intersects=geom)
            elif relation == "contains":
                qs = qs.filter(footprint__coveredby=geom)
            elif relation == "disjoint":
                qs = qs.filter(footprint__disjoint=geom)

        elif lon is not None and lat is not None and distance is not None:
            geom = Point(lon, lat)
            if relation == "intersects":
                qs = qs.filter(footprint__distance_lte=(geom, distance))
            elif relation == "contains":
                # TODO: right?, also only available on postgis
                qs = qs.filter(footprint__dwithin=(geom, distance))
            elif relation == "disjoint":
                qs = qs.filter(footprint__distance_gt=(geom, distance))
        elif lon is not None and lat is not None:
            geom = Point(lon, lat)
            if relation == "intersects":
                qs = qs.filter(footprint__intersects=geom)
            elif relation == "contains":
                qs = qs.filter(footprint__coveredby=geom)
            elif relation == "disjoint":
                qs = qs.filter(footprint__disjoint=geom)

        if uid:
            qs = qs.filter(identifier=uid)

        return qs

    def get_schema(self):
        return (
            dict(name="bbox", type="box"),
            dict(name="geom", type="geometry"),
            dict(name="lon", type="lon"),
            dict(name="lat", type="lat"),
            dict(name="r", type="radius"),
            dict(name="georel", type="relation",
                options=["intersects", "contains", "disjoint"]
            ),
            dict(name="uid", type="uid")
        )
Beispiel #15
0
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from django.contrib.gis.geos import Polygon, MultiPolygon

from eoxserver.core.util.xmltools import parse, NameSpace, NameSpaceMap
from eoxserver.core.util.timetools import parse_iso8601
from eoxserver.core.util.iteratortools import pairwise
from eoxserver.core import Component, implements
from eoxserver.core.decoders import xml
from eoxserver.resources.coverages.metadata.interfaces import (
    MetadataReaderInterface
)

NS_GMD = NameSpace("http://www.isotc211.org/2005/gmd", "gmd")
NS_GML = NameSpace("http://www.opengis.net/gml", "gml")
NS_GCO = NameSpace("http://www.isotc211.org/2005/gco", "gco")

nsmap = NameSpaceMap(NS_GMD, NS_GCO, NS_GML)


class InspireFormatReader(Component):
    implements(MetadataReaderInterface)

    def test(self, obj):
        tree = parse(obj)
        return tree is not None and tree.getroot().tag == NS_GMD("MD_Metadata")

    def read(self, obj):
        tree = parse(obj)
Beispiel #16
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ------------------------------------------------------------------------------

from lxml.builder import ElementMaker

from eoxserver.core.config import get_eoxserver_config
from eoxserver.core.util.xmltools import NameSpace, NameSpaceMap
from eoxserver.services.ows.common.config import CapabilitiesConfigReader
from eoxserver.services.ows.common.v20.encoders import OWS20Encoder
from eoxserver.services.ows.common.v20.encoders import ns_xlink, ns_ows

ns_dseo = NameSpace("http://www.opengis.net/dseo/1.0", "dseo")
nsmap = NameSpaceMap(ns_xlink, ns_ows, ns_dseo)

DSEO = ElementMaker(namespace=ns_dseo.uri, nsmap=nsmap)


class DSEO10CapabilitiesXMLEncoder(OWS20Encoder):
    def encode_capabilities(self, request, sections):
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        all_sections = "all" in sections
        caps = []
        if all_sections or "serviceidentification" in sections:
            caps.append(self.encode_service_identification("DSEO", conf, []))

        if all_sections or "serviceprovider" in sections:
Beispiel #17
0
class EarthObservationExtension(object):
    """ Implementation of the OpenSearch `'EO' extension
    <http://docs.opengeospatial.org/is/13-026r8/13-026r8.html>`_.
    """

    namespace = NameSpace("http://a9.com/-/opensearch/extensions/eo/1.0/",
                          "eo")

    def filter(self, qs, parameters):
        mapping, mapping_choices = filters.get_field_mapping_for_model(
            qs.model)
        decoder = EarthObservationExtensionDecoder(parameters)

        query_filters = []
        for filter_name, db_accessor in mapping.items():
            value = getattr(decoder, filter_name, None)

            if value:
                attr = filters.attribute(filter_name, mapping)
                if isinstance(value, list):
                    query_filters.append(filters.contains(attr, value))
                elif isinstance(value, dict):
                    if 'min' in value:
                        query_filters.append(
                            filters.compare(
                                attr, value['min'],
                                '>=' if value['min_inclusive'] else '>',
                                mapping_choices))
                    if 'max' in value:
                        query_filters.append(
                            filters.compare(
                                attr, value['max'],
                                '<=' if value['max_inclusive'] else '<',
                                mapping_choices))
                else:
                    query_filters.append(
                        filters.compare(attr, value, '=', mapping_choices))

        if query_filters:
            qs = qs.filter(filters.combine(query_filters, 'AND'))

        return qs

    def get_schema(self, collection=None, model_class=None):
        mapping, mapping_choices = filters.get_field_mapping_for_model(
            model_class or models.Product, True)

        schema = []
        summary = None
        if collection:
            summary = self._load_product_summary(collection)

        for key, value in mapping.items():
            param = dict(name=key, type=key)

            if summary:
                param_summary = summary.get(key)

                # leave out all parameters not present in the summary
                if not self._is_param_summary_valid(param_summary):
                    continue

                # insert information from the parameter summary
                if isinstance(param_summary, list):
                    param['options'] = param_summary
                elif isinstance(param_summary, dict):
                    min_ = param_summary.get('min')
                    max_ = param_summary.get('max')
                    if min_ is not None:
                        param['min'] = min_
                    if max_ is not None:
                        param['max'] = max_

            # use the mapping choices to get a list of options, if possible
            if 'options' not in param and value in mapping_choices:
                param['options'] = list(mapping_choices[value].keys())

            schema.append(param)

        return schema

    def _load_product_summary(self, collection):
        try:
            summary = json.loads(
                collection.collection_metadata.product_metadata_summary)
            return {
                filters._to_camel_case(key): value
                for key, value in summary.items()
            }
        except models.CollectionMetadata.DoesNotExist:
            pass
        return None

    def _is_param_summary_valid(self, param_summary):
        if not param_summary:
            return False

        elif isinstance(param_summary, dict):
            return param_summary.get('min') or param_summary.get('max')

        return True
Beispiel #18
0
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------
# pylint: disable=invalid-name, unused-import

from lxml.builder import ElementMaker
from eoxserver.core.util.xmltools import NameSpace, NameSpaceMap, ns_xsi
from eoxserver.services.ows.common.v11.encoders import (
    ns_xlink, ns_xml, ns_ows, OWS
)

# namespace declarations
ns_wps = NameSpace(
    "http://www.opengis.net/wps/1.0.0", "wps",
    "http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"
)

# namespace map
nsmap = NameSpaceMap(ns_xlink, ns_xml, ns_ows, ns_wps)

# Element factories
WPS = ElementMaker(namespace=ns_wps.uri, nsmap=nsmap)
NIL = ElementMaker() # nil-name