Пример #1
0
    def getEndpointServiceData(self, endpoint, forceRefresh):
        """Returns service data for an endpoint.
        """
        log.debug("getEndpointData called for %s", endpoint['wmsurl'])
        wmsUrl = self.makeProxiedUrl(endpoint['wmsurl'])
        wmcDoc = self.wmsCapabilityCache.getWmsCapabilities(wmsUrl, forceRefresh)

        dom = xml.dom.minidom.parseString(wmcDoc)
        # Get the namespace URI for the document root element.
        ns = dom.documentElement.namespaceURI

        # Get the version the WMS server responded with.
        wmsVersion = dom.documentElement.getAttribute('version')

        service = xml_util.getSingleChildByNameNS(dom.documentElement, ns, 'Service')
        if service == None:
            return None

        title = xml_util.getSingleChildTextByNameNS(service, ns, 'Title')
        abstract = xml_util.getSingleChildTextByNameNS(service, ns, 'Abstract')

        # Break internal references to facilitiate garbage collection.
        dom.unlink()

        return {
            'version': wmsVersion,
            'title': title,
            'abstract': abstract
            }
Пример #2
0
    def populateFromLayerElement(self, ns, layerEl, commonData):
        """Populates a WmsLayer instance from a WMS capabilities Layer element
        @param ns: namespace in capabilities document
        @param layerEl: Layer element
        @param commonData: dict of capabilities data that is not specific to the layer
        """
        self.title = xml_util.getSingleChildTextByNameNS(layerEl, ns, 'Title')
        self.name = xml_util.getSingleChildTextByNameNS(layerEl, ns, 'Name')
        self.abstract = xml_util.getSingleChildTextByNameNS(layerEl, ns, 'Abstract')
        self.getMapUrl = commonData['getMapUrl']
        self.getCapabilitiesUrl = commonData['getCapabilitiesUrl']
        self.getFeatureInfoUrl = commonData['getFeatureInfoUrl']
        self.wmsVersion = commonData['wmsVersion']
        self.getCoverageUrl = commonData['getCoverageUrl']

        # Parse Dimension element into attributes and list of values.
        # First look for pre-WMS 1.3.0 Extent elements.
        extents = {}
        for extentEl in xml_util.getChildrenByNameNS(layerEl, ns, 'Extent'):
            name = extentEl.getAttribute('name')
            extentData = extentEl.firstChild
            if extentData != None:
                extentStr = extentEl.firstChild.data.strip()
                extentValues = extentStr.split(',')
                extents[name] = extentValues

        # Find the Dimension elements.
        self.dimensions = []
        for dimensionEl in xml_util.getChildrenByNameNS(layerEl, ns, 'Dimension'):
            name = dimensionEl.getAttribute('name')
            units = dimensionEl.getAttribute('units')
            unitSymbol = dimensionEl.getAttribute('unitSymbol')
            default = dimensionEl.getAttribute('default')
            dimensionData = dimensionEl.firstChild
            if dimensionData != None:
                dimensionStr = dimensionEl.firstChild.data.strip()
                dimensionValues = dimensionStr.split(',')
            elif name in extents:
                dimensionValues = extents[name]
            else:
                dimensionValues = None
            if dimensionValues:
                dimension = {
                    'name': name,
                    'units': units,
                    'unitSymbol': unitSymbol,
                    'default': default,
                    'dimensionValues': dimensionValues
                    }
                self.dimensions.append(dimension)

        # Parse Style element into list of values.
        self.styles = []
        for styleEl in xml_util.getChildrenByNameNS(layerEl, ns, 'Style'):
            name = xml_util.getSingleChildTextByNameNS(styleEl, ns, 'Name')
            title = xml_util.getSingleChildTextByNameNS(styleEl, ns, 'Title')
            style = {
                'name': name,
                'title': title,
                }
            legendUrlEl = xml_util.getSingleChildByNameNS(styleEl, ns, 'LegendURL')
            if legendUrlEl != None:
                width = legendUrlEl.getAttribute('width')
                height = legendUrlEl.getAttribute('height')
                onlineResourceEl = xml_util.getSingleChildByNameNS(legendUrlEl, ns, 'OnlineResource')
                legendURL = onlineResourceEl.getAttributeNS(XLINK_URI, 'href')

                style['legendURL'] = {
                    'width': width,
                    'height': height,
                    'onlineResource': legendURL
                    }
            self.styles.append(style)

        self.getDisplayOptionsUrl = None
        for metadataUrlEl in xml_util.getChildrenByNameNS(layerEl, ns, 'MetadataURL'):
            metadataUrlType = metadataUrlEl.getAttribute('type')
            if metadataUrlType and (metadataUrlType == 'display_options') :
                if xml_util.getSingleChildTextByNameNS(metadataUrlEl, ns, 'Format') == 'application/json':
                    onlineResourceEl = xml_util.getSingleChildByNameNS(metadataUrlEl, ns, 'OnlineResource')
                    if onlineResourceEl:
                        self.getDisplayOptionsUrl = onlineResourceEl.getAttributeNS(XLINK_URI, 'href')