Ejemplo n.º 1
0
    def __init__(self, url, version='1.3.0', xml=None, username=None,
                 password=None, parse_remote_metadata=False, timeout=30,
                 headers=None):
        """initialize"""
        self.url = url
        self.username = username
        self.password = password
        self.version = version
        self.timeout = timeout
        self.headers = headers
        self._capabilities = None

        # Authentication handled by Reader
        reader = WMSCapabilitiesReader(self.version, url=self.url,
                                       un=self.username, pw=self.password,
                                       headers=headers)
        if xml:  # read from stored xml
            self._capabilities = reader.readString(xml)
        else:  # read from server
            self._capabilities = reader.read(self.url, timeout=self.timeout)

        self.request = reader.request

        # avoid building capabilities metadata if the
        # response is a ServiceExceptionReport
        se = self._capabilities.find('ServiceException')
        if se is not None:
            err_message = str(se.text).strip()
            raise ServiceException(err_message)

        # build metadata objects
        self._buildMetadata(parse_remote_metadata)
Ejemplo n.º 2
0
    def capcache_query(self):
        self.capcache_tstamp = datetime.utcnow()
        reader = WMSCapabilitiesReader(self.version, url=self.url,
                                       un=self.username,
                                       pw=self.password,
                                       headers=env.wmsclient.headers)
        self.capcache_xml = etree.tostring(reader.read(self.url))

        service = WebMapService(
            url=self.url, version=self.version,
            username=self.username,
            password=self.password,
            xml=str(self.capcache_xml))

        layers = []
        for lid, layer in service.contents.iteritems():
            layers.append(OrderedDict((
                ('id', lid), ('title', layer.title),
                ('index', map(int, layer.index.split('.'))),
            )))

        layers.sort(key=lambda i: i['index'])

        for l in layers:
            del l['index']

        data = OrderedDict((
            ('formats', service.getOperationByName('GetMap').formatOptions),
            ('layers', layers)))

        self.capcache_json = json.dumps(data, ensure_ascii=False)
Ejemplo n.º 3
0
    def __init__(self, url, version='1.1.1', xml=None, username=None, password=None,
                 parse_remote_metadata=False, headers=None, timeout=30, auth=None):
        """Initialize."""
        if auth:
            if username:
                auth.username = username
            if password:
                auth.password = password
        self.url = url
        self.version = version
        self.timeout = timeout
        self.headers = headers
        self._capabilities = None
        self.auth = auth or Authentication(username, password)

        # Authentication handled by Reader
        reader = WMSCapabilitiesReader(
            self.version, url=self.url, headers=headers, auth=self.auth)
        if xml:  # read from stored xml
            self._capabilities = reader.readString(xml)
        else:  # read from server
            self._capabilities = reader.read(self.url, timeout=self.timeout)

        self.request = reader.request

        # avoid building capabilities metadata if the
        # response is a ServiceExceptionReport
        se = self._capabilities.find('ServiceException')
        if se is not None:
            err_message = str(se.text).strip()
            raise ServiceException(err_message)

        # build metadata objects
        self._buildMetadata(parse_remote_metadata)
Ejemplo n.º 4
0
    def capcache_query(self):
        self.capcache_tstamp = datetime.utcnow()
        reader = WMSCapabilitiesReader(self.version,
                                       url=self.url,
                                       un=self.username,
                                       pw=self.password,
                                       headers=env.wmsclient.headers)
        try:
            xml = reader.read(self.url)
        except RequestException:
            raise ExternalServiceError("Could not read WMS capabilities.")
        self.capcache_xml = etree.tostring(xml)

        service = WebMapService(url=self.url,
                                version=self.version,
                                username=self.username,
                                password=self.password,
                                xml=self.capcache_xml)

        layers = []
        for lid, layer in service.contents.items():
            layers.append(
                OrderedDict((
                    ('id', lid),
                    ('title', layer.title),
                    ('index', [int(i) for i in layer.index.split('.')]),
                    ('bbox', layer.boundingBoxWGS84),  # may be None
                )))

        layers.sort(key=lambda i: i['index'])

        for layer in layers:
            del layer['index']

        data = OrderedDict(
            (('formats', service.getOperationByName('GetMap').formatOptions),
             ('layers', layers)))

        self.capcache_json = json.dumps(data, ensure_ascii=False)