예제 #1
0
def wms_direct(wms_url, xml=None, version=None, headers=None):
    version = version or WMS_VERSION
    try:
        wms = owslib_wms.WebMapService(wms_url, xml=xml.encode('utf-8') if xml is not None else xml, version=version, headers=headers)
    except requests.exceptions.HTTPError as exc:
        if exc.response.status_code == 404:
            return None
        raise exc
    return wms
예제 #2
0
def test_is_wms(url):
    """
    Checks if the provided URL actually points to a Web Map Service.
    Uses owslib WMS reader to parse the response.
    :param url:
    :return:
    """

    try:
        capabilities_url = wms.WMSCapabilitiesReader().capabilities_url(url)
        res = urllib2.urlopen(capabilities_url, None, 10)
        xml = res.read()
        s = wms.WebMapService(url, xml=xml)
        return isinstance(s.contents, dict) and s.contents != {}
    except Exception, e:
        log.error('WMS check for %s failed with exception: %s' % (url, str(e)))
예제 #3
0
    def _is_wms(self, url):
        '''
        Checks if the provided URL actually points to a Web Map Service.
        Uses owslib WMS reader to parse the response.
        '''
        try:
            capabilities_url = wms.WMSCapabilitiesReader().capabilities_url(
                url)
            res = urlopen(capabilities_url, None, 10)
            xml = res.read()

            s = wms.WebMapService(url, xml=xml)
            return isinstance(s.contents, dict) and s.contents != {}
        except Exception as e:
            log.error('WMS check for %s failed with exception: %s' %
                      (url, six.text_type(e)))
        return False
예제 #4
0
    def _is_wms(self, url):
        '''
        Checks if the provided URL actually points to a Web Map Service.
        Uses owslib WMS reader to parse the response.
        '''

        try:
            capabilities_url = wms.WMSCapabilitiesReader().capabilities_url(url)
            res = requests.get(capabilities_url, timeout=10)
            xml = res.text

            s = wms.WebMapService(url, xml=xml)
            raise Exception('is_wms: {}'.format(s.contents))
            return isinstance(s.contents, dict) and s.contents != {}
        except Exception as e:
            logger.error('WMS check for %s failed with exception: %s' % (url, str(e)))
        return False
def _try_wms_url(url, version='1.3'):
    # Here's a neat way to run this manually:
    # python -c "import logging; logging.basicConfig(level=logging.INFO); from ckanext.dgu.gemini_postprocess import _try_wms_url; print _try_wms_url('http://soilbio.nerc.ac.uk/datadiscovery/WebPage5.aspx')"
    '''Does a GetCapabilities request and returns whether it responded ok.

    Returns:
      True - got a WMS response that isn't a ServiceException
      False - got a different response, or got HTTP/WMS error
      None - socket timeout - host is simply not responding, and is so slow
             communicating there is no point trying it again
    '''

    try:
        capabilities_url = wms_capabilities_url(url, version)
        log.debug('WMS check url: %s', capabilities_url)
        try:
            res = requests.get(capabilities_url)
            res.raise_for_status()
            xml = res.content
        except requests.exceptions.RequestException, e:
            log.info('WMS check for %s failed due to HTTP error "%s".',
                     capabilities_url, e)
            return False
        if not xml.strip():
            log.info('WMS check for %s failed due to empty response')
            return False
        # owslib only supports reading WMS 1.1.1 (as of 10/2014)
        if version == '1.1.1':
            try:
                wms = owslib_wms.WebMapService(url, xml=xml)
            except AttributeError, e:
                # e.g. http://csw.data.gov.uk/geonetwork/srv/en/csw
                log.info(
                    'WMS check for %s failed due to GetCapabilities response not containing a required field',
                    url)
                return False
            except etree.XMLSyntaxError, e:
                # e.g. http://www.ordnancesurvey.co.uk/oswebsite/xml/atom/
                log.info(
                    'WMS check for %s failed parsing the XML response: %s',
                    url, e)
                return False
예제 #6
0
def get_whitelist_wms_layers():
    """
    This is necessary, since the harvester harvested 97 layers where as there are only 61 layers available.
    Get capabilities gives only 61 layers
    :return: tuple
    """
    _url = 'https://geonode.themimu.info/geoserver/wms'
    _version = "1.1.1"
    wms_layers = []
    try:
        identifiers = wms.WebMapService(_url, version=_version)
        wms_layers = list(
            identifiers.contents)  # first element is group hence ignore
        wms_layers.remove('group1')
    except ValueError as e:
        pass
    except urllib2.HTTPError as e:
        log.error("MIMU harvester url is unreachable")
        log.error(e)

    return tuple(wms_layers)
예제 #7
0
def get_wms(name):
    url = '%s/geoserver/wms' % GEOSERVER_BASE_URL
    return wms.WebMapService(url)[name]
예제 #8
0
 except httplib.HTTPException, e:
     log.info('WMS check for %s failed due to HTTP error "%s".',
              capabilities_url, e)
     return False
 if not xml.strip():
     log.info('WMS check for %s failed due to empty response')
     return False
 if len(xml) > MAX_BYTES_READ_DURING_WMS_CHECK:
     log.info(
         'WMS check for %s failed due to the response being too large (>%s bytes)',
         capabilities_url, MAX_BYTES_READ_DURING_WMS_CHECK)
     return False
 # owslib only supports reading WMS 1.1.1 (as of 10/2014)
 if version == '1.1.1':
     try:
         wms = owslib_wms.WebMapService(url, xml=xml)
     except AttributeError, e:
         # e.g. http://csw.data.gov.uk/geonetwork/srv/en/csw
         log.info(
             'WMS check for %s failed due to GetCapabilities response not containing a required field',
             url)
         return False
     except etree.XMLSyntaxError, e:
         # e.g. http://www.ordnancesurvey.co.uk/oswebsite/xml/atom/
         log.info(
             'WMS check for %s failed parsing the XML response: %s',
             url, e)
         return False
     except owslib_wms.ServiceException:
         # e.g. https://gatewaysecurity.ceh.ac.uk/wss/service/LCM2007_GB_25m_Raster/WSS
         log.info('WMS check for %s failed - OGC error message: %s',