Exemple #1
0
def test_wms_getfeatureinfo_130():
    wms = WebMapService(SERVICE_URL, version='1.3.0')

    res1 = wms.getfeatureinfo(
        layers=['bvv:lkr_ex'], srs='EPSG:31468',
        bbox=(4500000, 5500000, 4500500, 5500500), size=(500, 500), format='image/jpeg',
        info_format="text/html", xy=(250, 250))
    html_string1 = res1.read().decode("utf-8")
    assert 'lkr_ex' in html_string1
    assert 'gmd_ex' in html_string1

    res2 = wms.getfeatureinfo(
        layers=['bvv:lkr_ex', 'bvv:gmd_ex'], srs='EPSG:31468',
        bbox=(4500000, 5500000, 4500500, 5500500), size=(500, 500), format='image/jpeg',
        info_format="text/html", xy=(250, 250))
    html_string2 = res2.read().decode("utf-8")
    assert 'lkr_ex' in html_string2
    assert 'gmd_ex' in html_string2

    res3 = wms.getfeatureinfo(
        layers=['bvv:lkr_ex', 'bvv:gmd_ex'], srs='EPSG:31468',
        bbox=(4500000, 5500000, 4500500, 5500500), size=(500, 500), format='image/jpeg',
        query_layers=['bvv:lkr_ex'], info_format="text/html", xy=(250, 250))
    html_string3 = res3.read().decode("utf-8")
    assert 'lkr_ex' in html_string3
    assert 'gmd_ex' not in html_string3
Exemple #2
0
def test_wms_getfeatureinfo(ows_server):
    # Use owslib to confirm that we have a somewhat compliant WMS service
    wms = WebMapService(url=ows_server.url + "/wms", version="1.3.0")

    # Ensure that we have at least some layers available
    contents = list(wms.contents)
    test_layer_name = contents[0]
    test_layer = wms.contents[test_layer_name]

    bbox = test_layer.boundingBoxWGS84
    response = wms.getfeatureinfo(layers=[test_layer_name],
                                  srs='EPSG:4326',
                                  bbox=pytest.helpers.enclosed_bbox(bbox),
                                  size=(256, 256),
                                  format="image/png",
                                  query_layers=[test_layer_name],
                                  info_format="application/json",
                                  xy=(250, 250))

    assert response
    assert response.info()['Content-Type'] == 'application/json'
Exemple #3
0
class CMEMSWmsDataSource(BaseSource):
    def __init__(self, url, version='1.3.0'):
        self.url = url

        self.wms = WebMapService(url, version=version)
        self.response = None
        self.df = None
        self._time_indexes = {}

    def get_timeindex(self, layer):
        if layer not in self._time_indexes:
            i = get_timeindex(self.wms[layer].timepositions)
            self._time_indexes[layer] = i
        return self._time_indexes.get(layer)

    def get_df(self,
               layer,
               point,
               reftime=None,
               elevation=None,
               timedelta=None,
               timegap=None):
        """
        Query the WMS data source using the GetFeatureInfo method. It supports Elevation and Time dimensions.

        :param layer: WMS layer
        :param point: lat/long 2D array
        :param reftime: WMS Time range (eg. '2020-01-01/2020-12-01') or single date when used in together with timedelta or timegap parameters (eg. 2020-12-01)
        :param elevation: specify an elevation/depth level. If None default elevation will be returned.
        :param timedelta: time delta in days
        :param timegap: time gap in days
        :return: DataFrame with a datetime index and a "value" column
        """
        if reftime is not None:
            _time = reftime
        else:
            _time = date.today().isoformat()
        if timedelta is not None:
            _end = pd.to_datetime(_time)
            if timegap is not None:
                _end = _end - pd.Timedelta(days=timegap)
            _start = _end - pd.Timedelta(days=timedelta)
            time_index = self.get_timeindex(layer)
            _start = align_time(_start, time_index)
            _end = align_time(_end, time_index)
            _time = "{}/{}".format(_start.isoformat()[:-6],
                                   _end.isoformat()[:-6])

        bbox = (
            point[0] - 0.1,
            point[1] - 0.1,
            point[0] + 0.1,
            point[1] + 0.1,
        )
        _options = {
            'layers': [layer],
            'srs': 'EPSG:4326',
            'bbox': bbox,
            'size': (3, 3),
            'format': 'image/jpeg',
            'query_layers': [layer],
            'info_format': "text/xml",
            'xy': (1, 1)
        }
        if _time is not None:
            _options['time'] = _time
        if elevation is not None:
            _options['elevation'] = elevation

        logger.debug("request {} {} {} {}".format(layer, point, _time,
                                                  elevation))
        self.response = self.wms.getfeatureinfo(**_options)
        self.df = response2df(self.response)
        return self.df
Exemple #4
0
from owslib.wms import WebMapService
wms = WebMapService('http://212.26.144.110/geowebcache/service/wms', version='1.1.1')

wms.getfeatureinfo(layers='kadastr', query_layers='kadastr',styles='',
                   info_format='application/vnd.ogc.gml',srs='EPSG:900913')
__author__ = 'Juergen Weichand'

from owslib.wms import WebMapService
wms = WebMapService('http://geoserv.weichand.de:8080/geoserver/wms')

# GetMap (image/jpeg)
response = wms.getmap(
    layers=['bvv:gmd_ex'],
    srs='EPSG:31468',
    bbox=(4500000,5500000,4505000,5505000),
    size=(500,500),
    format='image/jpeg')

out = open('/tmp/getmap-response.jpeg', 'wb')
out.write(response.read())
out.close()

# GetFeatureInfo (text/html)
response = wms.getfeatureinfo(
    layers=['bvv:gmd_ex'],
    srs='EPSG:31468',
    bbox=(4500000,5500000,4505000,5505000),
    size=(500,500),
    format='image/jpeg',
    query_layers=['bvv:gmd_ex'],
    info_format="text/html",
    xy=(250,250))

out = open('/tmp/getfeatureinfo-response.html', 'wb')
out.write(response.read())
out.close()
#!/usr/bin/python
# -*- coding: UTF-8 -*-
__author__ = 'Juergen Weichand'

from owslib.wms import WebMapService
wms = WebMapService('http://geoserv.weichand.de:8080/geoserver/wms')

# GetMap (image/jpeg)
response = wms.getmap(layers=['bvv:gmd_ex'],
                      srs='EPSG:31468',
                      bbox=(4500000, 5500000, 4505000, 5505000),
                      size=(500, 500),
                      format='image/jpeg')

out = open('/tmp/getmap-response.jpeg', 'wb')
out.write(response.read())
out.close()

# GetFeatureInfo (text/html)
response = wms.getfeatureinfo(layers=['bvv:gmd_ex'],
                              srs='EPSG:31468',
                              bbox=(4500000, 5500000, 4505000, 5505000),
                              size=(500, 500),
                              format='image/jpeg',
                              query_layers=['bvv:gmd_ex'],
                              info_format="text/html",
                              xy=(250, 250))

out = open('/tmp/getfeatureinfo-response.html', 'wb')
out.write(response.read())
out.close()