Esempio n. 1
0
 def test_same_source(self):
     layers = [
         WMSSource(
             WMSClient(create_request({"url": "http://foo/", "layers": "a"}, {}))
         ),
         WMSSource(
             WMSClient(create_request({"url": "http://foo/", "layers": "b"}, {}))
         ),
     ]
     combined = combined_layers(layers, self.q)
     assert len(combined) == 1
     assert combined[0].client.request_template.params.layers == ["a", "b"]
Esempio n. 2
0
 def setup(self):
     self.file_cache = MockFileCache('/dev/null', 'png', lock_dir=tmp_lock_dir)
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockWMSClient()
     self.source = WMSSource(self.client)
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         meta_size=[2, 2], meta_buffer=10, minimize_meta_requests=True)
Esempio n. 3
0
 def source(self, mock_http_client):
     req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                            param={'layers': 'foo'})
     wms = WMSClient(req, http_client=mock_http_client)
     return WMSSource(wms,
                      supported_srs=[SRS(4326)],
                      image_opts=ImageOptions(resampling='bilinear'))
Esempio n. 4
0
 def tile_mgr(self, mock_file_cache, mock_wms_client, tile_locker):
     grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     source = WMSSource(mock_wms_client)
     return TileManager(grid, mock_file_cache, [source], 'png',
         meta_size=[2, 2], meta_buffer=10, minimize_meta_requests=True,
         locker=tile_locker,
     )
Esempio n. 5
0
    def test_get_map_with_res_range(self):
        res_range = resolution_range(1000, 10)
        self.source = WMSSource(self.client, res_range=res_range)
        self.locker = TileLocker(tmp_lock_dir, 10, "id")
        self.tile_mgr = TileManager(self.grid,
                                    self.file_cache, [self.source],
                                    'png',
                                    meta_size=[2, 2],
                                    meta_buffer=0,
                                    image_opts=self.image_opts,
                                    locker=self.locker)
        self.layer = CacheMapLayer(self.tile_mgr,
                                   image_opts=default_image_opts)

        try:
            result = self.layer.get_map(
                MapQuery(
                    (-20037508.34, -20037508.34, 20037508.34, 20037508.34),
                    (500, 500), SRS(900913), 'png'))
        except BlankImage:
            pass
        else:
            assert False, 'expected BlankImage exception'
        eq_(self.file_cache.stored_tiles, set())

        result = self.layer.get_map(
            MapQuery((0, 0, 10000, 10000), (50, 50), SRS(900913), 'png'))
        eq_(
            self.file_cache.stored_tiles,
            set([(512, 257, 10), (513, 256, 10), (512, 256, 10),
                 (513, 257, 10)]))
        eq_(result.size, (50, 50))
Esempio n. 6
0
    def test_get_map_with_res_range(self, mock_file_cache, mock_wms_client,
                                    tile_locker):
        grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
        res_range = resolution_range(1000, 10)
        source = WMSSource(mock_wms_client, res_range=res_range)
        image_opts = ImageOptions(resampling='nearest')
        tile_mgr = TileManager(grid,
                               mock_file_cache, [source],
                               'png',
                               meta_size=[2, 2],
                               meta_buffer=0,
                               image_opts=image_opts,
                               locker=tile_locker)
        layer = CacheMapLayer(tile_mgr, image_opts=default_image_opts)

        with pytest.raises(BlankImage):
            result = layer.get_map(
                MapQuery(
                    (-20037508.34, -20037508.34, 20037508.34, 20037508.34),
                    (500, 500), SRS(900913), 'png'))
        assert mock_file_cache.stored_tiles == set()

        result = layer.get_map(
            MapQuery((0, 0, 10000, 10000), (50, 50), SRS(900913), 'png'))
        assert mock_file_cache.stored_tiles == \
            set([(512, 257, 10), (513, 256, 10), (512, 256, 10), (513, 257, 10)])
        assert result.size == (50, 50)
Esempio n. 7
0
    def test_transformed_request_transparent(self):
        self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                    param={
                                        'layers': 'foo',
                                        'transparent': 'true'
                                    })
        self.wms = WMSClient(self.req, http_client=self.http)
        self.source = WMSSource(self.wms,
                                supported_srs=[SRS(4326)],
                                image_opts=ImageOptions(resampling='bilinear'))

        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512),
                       SRS(900913), 'png')
        resp = self.source.get_map(req)
        eq_(len(self.http.requested), 1)

        assert wms_query_eq(
            self.http.requested[0], TESTSERVER_URL +
            '/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
            '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326'
            '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true'
            '&BBOX=-1.79663056824,-1.7963362121,1.79663056824,1.7963362121')
        img = resp.as_image()
        assert img.mode in ('P', 'RGBA')
        img = img.convert('RGBA')
        eq_(img.getpixel((5, 5))[3], 0)
Esempio n. 8
0
 def source(self, mock_http_client):
     req_template = WMS111MapRequest(url='http://localhost/service?', param={
         'format': 'image/png', 'layers': 'foo'
     })
     client = WMSClient(req_template, http_client=mock_http_client)
     return WMSSource(client, supported_srs=SupportedSRS([SRS(4326)]),
         image_opts=ImageOptions(resampling='bilinear'))
Esempio n. 9
0
def create_wms_source(raster_source, app_state):
    url = raster_source.url
    username = raster_source.username
    password = raster_source.password

    http_client = create_http_client(username, password)

    coverage = coverage_from_geojson(raster_source.download_coverage)
    if coverage:
        # wrap to prevent partial tiles
        coverage = AlwaysContainsCoverage(coverage)

    request = create_request({
        'url': url,
        'layers': raster_source.layer
    }, {},
                             version='1.1.1')

    image_opts = ImageOptions(resampling='bicubic', transparent=True)

    supported_srs = None
    if raster_source.srs != 'EPSG:3857':
        supported_srs = [SRS(raster_source.srs)]

    client = WMSClient(request, http_client=http_client)
    source = WMSSource(
        client,
        coverage=coverage,
        supported_srs=supported_srs,
        image_opts=image_opts,
    )

    # wrap to prevent partial tiles
    source.extent = AlwaysContainsMapExtent(source.extent)
    return source
Esempio n. 10
0
 def setup(self):
     self.http_client = MockHTTPClient()
     self.req_template = WMS111MapRequest(url='http://localhost/service?', param={
         'format': 'image/png', 'layers': 'foo'
     })
     self.client = WMSClient(self.req_template, http_client=self.http_client)
     self.source = WMSSource(self.client, supported_srs=[SRS(4326)],
         image_opts=ImageOptions(resampling='bilinear'))
Esempio n. 11
0
 def layer(self, mock_file_cache, mock_wms_client, tile_locker):
     grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     source = WMSSource(mock_wms_client)
     image_opts = ImageOptions(resampling='nearest')
     tile_mgr = TileManager(grid, mock_file_cache, [source], 'png',
         meta_size=[2, 2], meta_buffer=0, image_opts=image_opts,
         locker=tile_locker)
     return CacheMapLayer(tile_mgr, image_opts=default_image_opts)
Esempio n. 12
0
 def setup(self):
     self.file_cache = MockFileCache('/dev/null', 'png', lock_dir=tmp_lock_dir)
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockWMSClient()
     self.source = WMSSource(self.client)
     self.image_opts = ImageOptions(format='image/png')
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         meta_size=[2, 2], meta_buffer=0, image_opts=self.image_opts)
Esempio n. 13
0
 def tile_mgr(self, mock_file_cache, tile_locker, mock_wms_client):
     grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     source = WMSSource(mock_wms_client)
     image_opts = ImageOptions(format='image/png')
     return TileManager(grid, mock_file_cache, [source], 'png',
         meta_size=[2, 2], meta_buffer=0, image_opts=image_opts,
         locker=tile_locker,
     )
Esempio n. 14
0
 def setup(self):
     self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                 param={'layers': 'foo'})
     self.http = MockHTTPClient()
     self.wms = WMSClient(self.req, http_client=self.http)
     self.source = WMSSource(self.wms,
                             supported_srs=[SRS(4326)],
                             image_opts=ImageOptions(resampling='bilinear'))
Esempio n. 15
0
 def test_same_source(self):
     layers = [
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://foo/',
                     'layers': 'a'
                 }, {}))),
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://foo/',
                     'layers': 'b'
                 }, {}))),
     ]
     combined = combined_layers(layers, self.q)
     eq_(len(combined), 1)
     eq_(combined[0].client.request_template.params.layers, ['a', 'b'])
Esempio n. 16
0
 def setup(self):
     self.file_cache = MockFileCache('/dev/null', 'png', lock_dir=tmp_lock_dir)
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockWMSClient()
     self.source = WMSSource(self.client)
     self.image_opts = ImageOptions(resampling='nearest')
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         meta_size=[2, 2], meta_buffer=0, image_opts=self.image_opts)
     self.layer = CacheMapLayer(self.tile_mgr, image_opts=default_image_opts)
Esempio n. 17
0
 def setup(self):
     self.req_template = WMS111MapRequest(url='http://%s:%d/service?' %
                                          TEST_SERVER_ADDRESS,
                                          param={
                                              'format': 'image/png',
                                              'layers': 'foo'
                                          })
     self.client = WMSClient(self.req_template)
     self.source = WMSSource(self.client)
Esempio n. 18
0
 def setup(self):
     self.file_cache = MockFileCache('/dev/null', 'png')
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockWMSClient()
     self.source = WMSSource(self.client)
     self.image_opts = ImageOptions(resampling='nearest', format='png')
     self.locker = TileLocker(tmp_lock_dir, 10, "id")
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         meta_size=[1, 1], meta_buffer=0, image_opts=self.image_opts,
         locker=self.locker)
     self.layer = CacheMapLayer(self.tile_mgr, image_opts=default_image_opts)
     self.layer.extent = BBOXCoverage([0, 0, 90, 45], SRS(4326)).extent
Esempio n. 19
0
 def test_mixed_hosts(self):
     layers = [
         WMSSource(
             WMSClient(create_request({"url": "http://foo/", "layers": "a"}, {}))
         ),
         WMSSource(
             WMSClient(create_request({"url": "http://foo/", "layers": "b"}, {}))
         ),
         WMSSource(
             WMSClient(create_request({"url": "http://bar/", "layers": "c"}, {}))
         ),
         WMSSource(
             WMSClient(create_request({"url": "http://bar/", "layers": "d"}, {}))
         ),
         WMSSource(
             WMSClient(create_request({"url": "http://foo/", "layers": "e"}, {}))
         ),
         WMSSource(
             WMSClient(create_request({"url": "http://foo/", "layers": "f"}, {}))
         ),
     ]
     combined = combined_layers(layers, self.q)
     assert len(combined) == 3
     assert combined[0].client.request_template.params.layers == ["a", "b"]
     assert combined[1].client.request_template.params.layers == ["c", "d"]
     assert combined[2].client.request_template.params.layers == ["e", "f"]
Esempio n. 20
0
    def test_mixed_params(self):
        layers = [
            WMSSource(
                WMSClient(create_request({"url": "http://foo/", "layers": "a"}, {}))
            ),
            WMSSource(
                WMSClient(create_request({"url": "http://foo/", "layers": "b"}, {}))
            ),
            WMSSource(
                WMSClient(create_request({"url": "http://foo/", "layers": "c"}, {}))
            ),
            WMSSource(
                WMSClient(create_request({"url": "http://foo/", "layers": "d"}, {}))
            ),
            WMSSource(
                WMSClient(create_request({"url": "http://foo/", "layers": "e"}, {}))
            ),
            WMSSource(
                WMSClient(create_request({"url": "http://foo/", "layers": "f"}, {}))
            ),
        ]

        layers[0].supported_srs = ["EPSG:4326"]
        layers[1].supported_srs = ["EPSG:4326"]

        layers[2].supported_formats = ["image/png"]
        layers[3].supported_formats = ["image/png"]

        combined = combined_layers(layers, self.q)
        assert len(combined) == 3
        assert combined[0].client.request_template.params.layers == ["a", "b"]
        assert combined[1].client.request_template.params.layers == ["c", "d"]
        assert combined[2].client.request_template.params.layers == ["e", "f"]
Esempio n. 21
0
    def test_similar_srs(self):
        # request in 3857 and source supports only 900913
        # 3857 and 900913 are equal but the client requests must use 900913
        self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                    param={'layers':'foo', 'transparent': 'true'})
        self.wms = WMSClient(self.req, http_client=self.http)
        self.source = WMSSource(self.wms, supported_srs=[SRS(900913)],
            image_opts=ImageOptions(resampling='bilinear'))
        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(3857), 'png')
        self.source.get_map(req)
        eq_(len(self.http.requested), 1)

        assert_query_eq(self.http.requested[0],
            TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                           '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A900913'
                           '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true'
                           '&BBOX=-200000,-200000,200000,200000')
Esempio n. 22
0
    def test_http_error_handler(self, client):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=True)
        error_handler.add_handler(400, (0, 0, 0), cacheable=False)
        source = WMSSource(client, error_handler=error_handler)
        expected_req = [
            (
                {
                    'path':
                    r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                    '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326'
                    '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512&STYLES='
                },
                {
                    'body': b'error',
                    'status': 500,
                    'headers': {
                        'content-type': 'text/plain'
                    },
                },
            ),
            (
                {
                    'path':
                    r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                    '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326'
                    '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512&STYLES='
                },
                {
                    'body': b'error',
                    'status': 400,
                    'headers': {
                        'content-type': 'text/plain'
                    },
                },
            ),
        ]
        with mock_httpd(TEST_SERVER_ADDRESS, expected_req):
            query = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
            resp = source.get_map(query)
            assert resp.cacheable
            assert resp.as_image().getcolors() == [((512 * 512), (255, 0, 0))]

            resp = source.get_map(query)
            assert not resp.cacheable
            assert resp.as_image().getcolors() == [((512 * 512), (0, 0, 0))]
Esempio n. 23
0
    def test_mixed_params(self):
        layers = [
            WMSSource(
                WMSClient(
                    create_request({
                        'url': 'http://foo/',
                        'layers': 'a'
                    }, {}))),
            WMSSource(
                WMSClient(
                    create_request({
                        'url': 'http://foo/',
                        'layers': 'b'
                    }, {}))),
            WMSSource(
                WMSClient(
                    create_request({
                        'url': 'http://foo/',
                        'layers': 'c'
                    }, {}))),
            WMSSource(
                WMSClient(
                    create_request({
                        'url': 'http://foo/',
                        'layers': 'd'
                    }, {}))),
            WMSSource(
                WMSClient(
                    create_request({
                        'url': 'http://foo/',
                        'layers': 'e'
                    }, {}))),
            WMSSource(
                WMSClient(
                    create_request({
                        'url': 'http://foo/',
                        'layers': 'f'
                    }, {}))),
        ]

        layers[0].supported_srs = ["EPSG:4326"]
        layers[1].supported_srs = ["EPSG:4326"]

        layers[2].supported_formats = ["image/png"]
        layers[3].supported_formats = ["image/png"]

        combined = combined_layers(layers, self.q)
        eq_(len(combined), 3)
        eq_(combined[0].client.request_template.params.layers, ['a', 'b'])
        eq_(combined[1].client.request_template.params.layers, ['c', 'd'])
        eq_(combined[2].client.request_template.params.layers, ['e', 'f'])
Esempio n. 24
0
 def test_mixed_hosts(self):
     layers = [
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://foo/',
                     'layers': 'a'
                 }, {}))),
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://foo/',
                     'layers': 'b'
                 }, {}))),
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://bar/',
                     'layers': 'c'
                 }, {}))),
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://bar/',
                     'layers': 'd'
                 }, {}))),
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://foo/',
                     'layers': 'e'
                 }, {}))),
         WMSSource(
             WMSClient(
                 create_request({
                     'url': 'http://foo/',
                     'layers': 'f'
                 }, {}))),
     ]
     combined = combined_layers(layers, self.q)
     eq_(len(combined), 3)
     eq_(combined[0].client.request_template.params.layers, ['a', 'b'])
     eq_(combined[1].client.request_template.params.layers, ['c', 'd'])
     eq_(combined[2].client.request_template.params.layers, ['e', 'f'])
Esempio n. 25
0
 def source(self, client):
     return WMSSource(client)
Esempio n. 26
0
 def layer(self, mock_wms_client):
     source = WMSSource(mock_wms_client)
     return DirectMapLayer(source, GLOBAL_GEOGRAPHIC_EXTENT)
Esempio n. 27
0
 def setup(self):
     self.client = MockWMSClient()
     self.source = WMSSource(self.client)
     self.layer = DirectMapLayer(self.source, GLOBAL_GEOGRAPHIC_EXTENT)
Esempio n. 28
0
 def source(self, mock_wms_client):
     return WMSSource(mock_wms_client)