Esempio n. 1
0
    def render(self, layer_groups, request_values, request, **options):
        config = CapabilitiesConfigReader(get_eoxserver_config())
        http_service_url = get_http_service_url(request)
        map_ = ms.Map()
        map_.setMetaData({
            "enable_request": "*",
            "onlineresource": http_service_url,
        }, namespace="ows")

        map_.setMetaData("wms_getfeatureinfo_formatlist", "text/html")
        map_.setProjection("EPSG:4326")

        session = self.setup_map(layer_groups, map_, options)

        # check if the required format is EO O&M
        frmt = pop_param(request_values, "info_format")
        use_eoom = False
        if frmt in ("application/xml", "text/xml"):
            request_values.append(("info_format", "application/vnd.ogc.gml"))
            use_eoom = True
        else:
            request_values.append(("info_format", frmt))
        
        with session:
            request = ms.create_request(request_values)
            raw_result = map_.dispatch(request)
            result = result_set_from_raw_data(raw_result)

            if not use_eoom:
                # just return the response
                return result, get_content_type(result)
            else:
                # do a postprocessing step and get all identifiers in order
                # to encode them with EO O&M
                decoder = GMLFeatureDecoder(result[0].data_file.read())
                identifiers = decoder.identifiers
                coverages = models.Coverage.objects.filter(
                    identifier__in=identifiers
                )

                # sort the result with the returned order of coverages
                lookup_table = dict((c.identifier, c) for c in coverages)
                coverages = [
                    lookup_table[identifier] for identifier in identifiers
                ]

                # encode the coverages with the EO O&M 
                encoder = WCS20EOXMLEncoder()

                return [
                    ResultBuffer(
                        encoder.serialize(
                            encoder.encode_coverage_descriptions(coverages)
                        ), encoder.content_type
                    )
                ], encoder.content_type
Esempio n. 2
0
    def encode_operations_metadata(self, request):
        component = ServiceComponent(env)
        versions = ("2.0.0", "2.0.1")
        get_handlers = component.query_service_handlers(
            service="WCS", versions=versions, method="GET"
        )
        post_handlers = component.query_service_handlers(
            service="WCS", versions=versions, method="POST"
        )
        all_handlers = sorted(
            set(get_handlers + post_handlers),
            key=lambda h: (getattr(h, "index", 10000), h.request)
        )

        http_service_url = get_http_service_url(request)

        operations = []
        for handler in all_handlers:
            methods = []
            if handler in get_handlers:
                methods.append(
                    self.encode_reference("Get", http_service_url)
                )
            if handler in post_handlers:
                post = self.encode_reference("Post", http_service_url)
                post.append(
                    OWS("Constraint",
                        OWS("AllowedValues",
                            OWS("Value", "XML")
                        ), name="PostEncoding"
                    )
                )
                methods.append(post)

            operations.append(
                OWS("Operation",
                    OWS("DCP",
                        OWS("HTTP", *methods)
                    ),
                    # apply default values as constraints
                    *[
                        OWS("Constraint",
                            OWS("NoValues"),
                            OWS("DefaultValue", str(default)),
                            name=name
                        ) for name, default
                        in getattr(handler, "constraints", {}).items()
                    ],
                    name=handler.request
                )
            )

        return OWS("OperationsMetadata", *operations)
Esempio n. 3
0
    def encode_operations_metadata(self, request):
        component = ServiceComponent(env)
        versions = ("2.0.0", "2.0.1")
        get_handlers = component.query_service_handlers(service="WCS",
                                                        versions=versions,
                                                        method="GET")
        post_handlers = component.query_service_handlers(service="WCS",
                                                         versions=versions,
                                                         method="POST")
        all_handlers = sorted(set(get_handlers + post_handlers),
                              key=lambda h:
                              (getattr(h, "index", 10000), h.request))

        http_service_url = get_http_service_url(request)

        operations = []
        for handler in all_handlers:
            methods = []
            if handler in get_handlers:
                methods.append(self.encode_reference("Get", http_service_url))
            if handler in post_handlers:
                post = self.encode_reference("Post", http_service_url)
                post.append(
                    OWS("Constraint",
                        OWS("AllowedValues", OWS("Value", "XML")),
                        name="PostEncoding"))
                methods.append(post)

            operations.append(
                OWS(
                    "Operation",
                    OWS("DCP", OWS("HTTP", *methods)),
                    # apply default values as constraints
                    *[
                        OWS("Constraint",
                            OWS("NoValues"),
                            OWS("DefaultValue", str(default)),
                            name=name) for name, default in getattr(
                                handler, "constraints", {}).items()
                    ],
                    name=handler.request))

        return OWS("OperationsMetadata", *operations)
Esempio n. 4
0
 def get_http_service_url(self, request):
     conf = self.get_conf()
     if conf.http_service_url:
         return conf.http_service_url
     from eoxserver.services.urls import get_http_service_url
     return get_http_service_url(request)
Esempio n. 5
0
    def render(self, params):
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        http_service_url = get_http_service_url(params.http_request)

        map_ = Map()
        map_.setMetaData(
            {
                "enable_request": "*",
                "onlineresource": http_service_url,
                "service_onlineresource": conf.onlineresource,
                "updateSequence": conf.update_sequence,
                "name": conf.name,
                "title": conf.title,
                "label": conf.title,
                "abstract": conf.abstract,
                "accessconstraints": conf.access_constraints,
                "addresstype": "",
                "address": conf.delivery_point,
                "stateorprovince": conf.administrative_area,
                "city": conf.city,
                "postcode": conf.postal_code,
                "country": conf.country,
                "contactelectronicmailaddress": conf.electronic_mail_address,
                "contactfacsimiletelephone": conf.phone_facsimile,
                "contactvoicetelephone": conf.phone_voice,
                "contactperson": conf.individual_name,
                "contactorganization": conf.provider_name,
                "contactposition": conf.position_name,
                "role": conf.role,
                "hoursofservice": conf.hours_of_service,
                "contactinstructions": conf.contact_instructions,
                "fees": conf.fees,
                "keywordlist": ",".join(conf.keywords),
                "formats": " ".join([f.wcs10name for f in self.get_wcs_formats()]),
                "srs": " ".join(crss.getSupportedCRS_WCS(format_function=crss.asShortCode)),
            },
            namespace="ows",
        )
        map_.setProjection("EPSG:4326")

        for outputformat in self.get_all_outputformats(False):
            map_.appendOutputFormat(outputformat)

        for coverage in params.coverages:
            layer = Layer(coverage.identifier)

            layer.setProjection(coverage.spatial_reference.proj)
            extent = coverage.extent
            size = coverage.size
            resolution = ((extent[2] - extent[0]) / float(size[0]), (extent[1] - extent[3]) / float(size[1]))

            layer.setExtent(*extent)
            layer.setMetaData(
                {
                    "title": coverage.identifier,
                    "label": coverage.identifier,
                    "extent": "%.10g %.10g %.10g %.10g" % extent,
                    "resolution": "%.10g %.10g" % resolution,
                    "size": "%d %d" % size,
                    "formats": " ".join([f.wcs10name for f in self.get_wcs_formats()]),
                    "srs": " ".join(crss.getSupportedCRS_WCS(format_function=crss.asShortCode)),
                },
                namespace="wcs",
            )

            map_.insertLayer(layer)

        request = create_request(params)
        request.setParameter("version", params.version)
        raw_result = map_.dispatch(request)
        result = result_set_from_raw_data(raw_result)
        return result
Esempio n. 6
0
    def render(self, params):
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        http_service_url = get_http_service_url(params.http_request)

        map_ = Map()
        map_.setMetaData(
            {
                "enable_request":
                "*",
                "onlineresource":
                http_service_url,
                "service_onlineresource":
                conf.onlineresource,
                "updateSequence":
                conf.update_sequence,
                "name":
                conf.name,
                "title":
                conf.title,
                "label":
                conf.title,
                "abstract":
                conf.abstract,
                "accessconstraints":
                conf.access_constraints,
                "addresstype":
                "",
                "address":
                conf.delivery_point,
                "stateorprovince":
                conf.administrative_area,
                "city":
                conf.city,
                "postcode":
                conf.postal_code,
                "country":
                conf.country,
                "contactelectronicmailaddress":
                conf.electronic_mail_address,
                "contactfacsimiletelephone":
                conf.phone_facsimile,
                "contactvoicetelephone":
                conf.phone_voice,
                "contactperson":
                conf.individual_name,
                "contactorganization":
                conf.provider_name,
                "contactposition":
                conf.position_name,
                "role":
                conf.role,
                "hoursofservice":
                conf.hours_of_service,
                "contactinstructions":
                conf.contact_instructions,
                "fees":
                conf.fees,
                "keywordlist":
                ",".join(conf.keywords),
                "formats":
                " ".join([f.wcs10name for f in self.get_wcs_formats()]),
                "srs":
                " ".join(
                    crss.getSupportedCRS_WCS(
                        format_function=crss.asShortCode)),
            },
            namespace="ows")
        map_.setProjection("EPSG:4326")

        for outputformat in self.get_all_outputformats(False):
            map_.appendOutputFormat(outputformat)

        for coverage in params.coverages:
            layer = Layer(coverage.identifier)

            render_coverage = Coverage.from_model(coverage)
            layer.setProjection(render_coverage.grid.spatial_reference.proj)
            extent = render_coverage.extent
            size = render_coverage.size
            resolution = ((extent[2] - extent[0]) / float(size[0]),
                          (extent[1] - extent[3]) / float(size[1]))

            layer.setExtent(*extent)
            layer.setMetaData(
                {
                    "title":
                    coverage.identifier,
                    "label":
                    coverage.identifier,
                    "extent":
                    "%.10g %.10g %.10g %.10g" % extent,
                    "resolution":
                    "%.10g %.10g" % resolution,
                    "size":
                    "%d %d" % size,
                    "formats":
                    " ".join([f.wcs10name for f in self.get_wcs_formats()]),
                    "srs":
                    " ".join(
                        crss.getSupportedCRS_WCS(
                            format_function=crss.asShortCode)),
                },
                namespace="wcs")

            map_.insertLayer(layer)

        request = create_request(params)
        request.setParameter("version", params.version)
        raw_result = map_.dispatch(request)
        result = result_set_from_raw_data(raw_result)
        xml_result = etree.fromstring(result[0].data)

        for elem in xml_result.xpath('//*[local-name() = "metadataLink"]'):
            elem.getparent().remove(elem)

        # Add CQL parameter to GetCapabilities operation
        for elem in xml_result.xpath(
                '//*[local-name() = "Operation"][@name = "GetCapabilities"]'):
            ows = elem.nsmap['ows']
            param = etree.SubElement(elem, '{%s}Parameter' % ows)
            param.attrib['name'] = 'cql'
            etree.SubElement(param, '{%s}AnyValue' % ows)

        xml_result_data = etree.tostring(xml_result,
                                         pretty_print=True,
                                         encoding='UTF-8',
                                         xml_declaration=True)

        result[0] = ResultBuffer(xml_result_data, result[0].content_type)
        return result
    def render(self, collections, coverages, request_values, request):
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        suffixes = self.suffixes

        http_service_url = get_http_service_url(request)

        map_ = Map()
        map_.setMetaData({
            "enable_request": "*",
            "onlineresource": http_service_url,
            "service_onlineresource": conf.onlineresource,
            "updateSequence": conf.update_sequence,
            "name": conf.name,
            "title": conf.title,
            "abstract": conf.abstract,
            "accessconstraints": conf.access_constraints,
            "addresstype": "postal",
            "address": conf.delivery_point,
            "stateorprovince": conf.administrative_area,
            "city": conf.city,
            "postcode": conf.postal_code,
            "country": conf.country,
            "contactelectronicmailaddress": conf.electronic_mail_address,
            "contactfacsimiletelephone": conf.phone_facsimile,
            "contactvoicetelephone": conf.phone_voice,
            "contactperson": conf.individual_name,
            "contactorganization": conf.provider_name,
            "contactposition": conf.position_name,
            "fees": conf.fees,
            "keywordlist": ",".join(conf.keywords),
            "srs": " ".join(crss.getSupportedCRS_WCS(format_function=crss.asShortCode)),
        }, namespace="ows")
        map_.setProjection("EPSG:4326")
        map_.setMetaData({
            "getmap_formatlist": ",".join([f.mimeType for f in self.get_wms_formats()]),
            "getfeatureinfo_formatlist": "text/html,application/vnd.ogc.gml,text/plain",
        }, namespace="wms")

        map_extent = None

        for collection in collections:
            group_name = None
            
            # calculate extent and timextent for every collection
            extent = collection.extent_wgs84
            # save overall map extent
            map_extent = self.join_extents(map_extent, extent)

            eo_objects = collection.eo_objects.filter(
                begin_time__isnull=False, end_time__isnull=False
            )
            timeextent = ",".join(
                map(
                    lambda o: (
                        "/".join(
                            map(isoformat, o.time_extent)
                        ) + "/PT1S"
                    ), eo_objects
                )
            )

            if len(suffixes) > 1:
                # create group layer, if there is more than one suffix for this 
                # collection
                group_name = collection.identifier + "_group"
                group_layer = Layer(group_name)
                group_layer.setMetaData({
                    "title": group_name,
                    "abstract": group_name,
                    "extent": " ".join(map(str, extent)),
                }, namespace="wms")

                minx, miny, maxx, maxy = extent
                group_layer.setExtent(minx, miny, maxx, maxy)

                # add default style
                default_class = Class("default")
                default_style= Style("default")
                default_class.insertStyle(default_style)
                group_layer.insertClass(default_class)

                map_.insertLayer(group_layer)

            for suffix in suffixes:
                layer_name = collection.identifier + (suffix or "")
                layer = Layer(layer_name)
                if group_name:
                    layer.setMetaData({
                        "layer_group": "/" + group_name
                    }, namespace="wms")

                layer.setMetaData({
                    "title": layer_name,
                    "abstract": layer_name,
                    "extent": " ".join(map(str, extent)),
                    "timeextent": timeextent,
                }, namespace="wms")
                map_.insertLayer(layer)

        for coverage in coverages:
            extent = coverage.extent_wgs84
            minx, miny, maxx, maxy = extent
            # save overall map extent
            map_extent = self.join_extents(map_extent, extent)

            layer_name = coverage.identifier
            layer = Layer(layer_name)
            layer.setMetaData({
                "title": layer_name,
                "abstract": layer_name,
                "extent": " ".join(map(str, extent)),
            }, namespace="wms")
            minx, miny, maxx, maxy = extent
            layer.setExtent(minx, miny, maxx, maxy)

            map_.insertLayer(layer)

        # set the map_extent to a reasonable default value
        # in case there is no coverage or collection
        if map_extent is None : 
            map_extent = ( 0.0, 0.0, 1.0, 1.0 )

        map_minx, map_miny, map_maxx, map_maxy = map_extent
        map_.setExtent(map_minx, map_miny, map_maxx, map_maxy)

        request = create_request(request_values)
        raw_result = map_.dispatch(request)
        result = result_set_from_raw_data(raw_result)
        return result, get_content_type(result)
    def render(self, params):
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        http_service_url = get_http_service_url(params.http_request)

        map_ = Map()
        map_.setMetaData({
            "enable_request": "*",
            "onlineresource": http_service_url,
            "service_onlineresource": conf.onlineresource,
            "updateSequence": conf.update_sequence,
            "name": conf.name,
            "title": conf.title,
            "label": conf.title,
            "abstract": conf.abstract,
            "accessconstraints": conf.access_constraints,
            "addresstype": "",
            "address": conf.delivery_point,
            "stateorprovince": conf.administrative_area,
            "city": conf.city,
            "postcode": conf.postal_code,
            "country": conf.country,
            "contactelectronicmailaddress": conf.electronic_mail_address,
            "contactfacsimiletelephone": conf.phone_facsimile,
            "contactvoicetelephone": conf.phone_voice,
            "contactperson": conf.individual_name,
            "contactorganization": conf.provider_name,
            "contactposition": conf.position_name,
            "role": conf.role,
            "hoursofservice": conf.hours_of_service,
            "contactinstructions": conf.contact_instructions,
            "fees": conf.fees,
            "keywordlist": ",".join(conf.keywords),
            "formats": " ".join([f.wcs10name for f in self.get_wcs_formats()]),
            "srs": " ".join(crss.getSupportedCRS_WCS(format_function=crss.asShortCode)),
        }, namespace="ows")
        map_.setProjection("EPSG:4326")

        for outputformat in self.get_all_outputformats(False):
            map_.appendOutputFormat(outputformat)

        for coverage in params.coverages:
            layer = Layer(coverage.identifier)

            layer.setProjection(coverage.spatial_reference.proj)
            extent = coverage.extent
            size = coverage.size
            resolution = ((extent[2] - extent[0]) / float(size[0]),
                          (extent[1] - extent[3]) / float(size[1]))

            layer.setExtent(*extent)
            layer.setMetaData({
                "title": coverage.identifier,
                "label": coverage.identifier,
                "extent": "%.10g %.10g %.10g %.10g" % extent,
                "resolution": "%.10g %.10g" % resolution,
                "size": "%d %d" % size,
                "formats": " ".join([f.wcs10name for f in self.get_wcs_formats()]),
                "srs": " ".join(crss.getSupportedCRS_WCS(format_function=crss.asShortCode)),
            }, namespace="wcs")

            map_.insertLayer(layer)

        request = create_request(params)
        request.setParameter("version", params.version)
        raw_result = map_.dispatch(request)
        result = result_set_from_raw_data(raw_result)
        return result
Esempio n. 9
0
    def render(self, collections, coverages, request_values, request):
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        suffixes = self.suffixes

        http_service_url = get_http_service_url(request)

        map_ = Map()
        map_.setMetaData(
            {
                "enable_request":
                "*",
                "onlineresource":
                http_service_url,
                "service_onlineresource":
                conf.onlineresource,
                "updateSequence":
                conf.update_sequence,
                "name":
                conf.name,
                "title":
                conf.title,
                "abstract":
                conf.abstract,
                "accessconstraints":
                conf.access_constraints,
                "addresstype":
                "postal",
                "address":
                conf.delivery_point,
                "stateorprovince":
                conf.administrative_area,
                "city":
                conf.city,
                "postcode":
                conf.postal_code,
                "country":
                conf.country,
                "contactelectronicmailaddress":
                conf.electronic_mail_address,
                "contactfacsimiletelephone":
                conf.phone_facsimile,
                "contactvoicetelephone":
                conf.phone_voice,
                "contactperson":
                conf.individual_name,
                "contactorganization":
                conf.provider_name,
                "contactposition":
                conf.position_name,
                "fees":
                conf.fees,
                "keywordlist":
                ",".join(conf.keywords),
                "srs":
                " ".join(
                    crss.getSupportedCRS_WCS(
                        format_function=crss.asShortCode)),
            },
            namespace="ows")
        map_.setProjection("EPSG:4326")
        map_.setMetaData(
            {
                "getmap_formatlist":
                ",".join([f.mimeType for f in self.get_wms_formats()]),
                "getfeatureinfo_formatlist":
                "text/html,application/vnd.ogc.gml,text/plain",
            },
            namespace="wms")

        map_extent = None

        for collection in collections:
            group_name = None

            # calculate extent and timextent for every collection
            extent = collection.extent_wgs84
            # save overall map extent
            map_extent = self.join_extents(map_extent, extent)

            eo_objects = collection.eo_objects.filter(begin_time__isnull=False,
                                                      end_time__isnull=False)
            timeextent = ",".join(
                map(
                    lambda o:
                    ("/".join(map(isoformat, o.time_extent)) + "/PT1S"),
                    eo_objects))

            if len(suffixes) > 1:
                # create group layer, if there is more than one suffix for this
                # collection
                group_name = collection.identifier + "_group"
                group_layer = Layer(group_name)
                group_layer.setMetaData(
                    {
                        "title": group_name,
                        "abstract": group_name,
                        "extent": " ".join(map(str, extent)),
                    },
                    namespace="wms")

                minx, miny, maxx, maxy = extent
                group_layer.setExtent(minx, miny, maxx, maxy)

                # add default style
                default_class = Class("default")
                default_style = Style("default")
                default_class.insertStyle(default_style)
                group_layer.insertClass(default_class)

                map_.insertLayer(group_layer)

            for suffix in suffixes:
                layer_name = collection.identifier + (suffix or "")
                layer = Layer(layer_name)
                if group_name:
                    layer.setMetaData({"layer_group": "/" + group_name},
                                      namespace="wms")

                layer.setMetaData(
                    {
                        "title": layer_name,
                        "abstract": layer_name,
                        "extent": " ".join(map(str, extent)),
                        "timeextent": timeextent,
                    },
                    namespace="wms")
                map_.insertLayer(layer)

        for coverage in coverages:
            extent = coverage.extent_wgs84
            minx, miny, maxx, maxy = extent
            # save overall map extent
            map_extent = self.join_extents(map_extent, extent)

            layer_name = coverage.identifier
            layer = Layer(layer_name)
            layer.setMetaData(
                {
                    "title": layer_name,
                    "abstract": layer_name,
                    "extent": " ".join(map(str, extent)),
                },
                namespace="wms")
            minx, miny, maxx, maxy = extent
            layer.setExtent(minx, miny, maxx, maxy)

            map_.insertLayer(layer)

        # set the map_extent to a reasonable default value
        # in case there is no coverage or collection
        if map_extent is None:
            map_extent = (0.0, 0.0, 1.0, 1.0)

        map_minx, map_miny, map_maxx, map_maxy = map_extent
        map_.setExtent(map_minx, map_miny, map_maxx, map_maxy)

        request = create_request(request_values)
        raw_result = map_.dispatch(request)
        result = result_set_from_raw_data(raw_result)
        return result, get_content_type(result)