class TestCacheMapLayerWithExtent(object): 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', format='png') self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png', meta_size=[1, 1], meta_buffer=0, image_opts=self.image_opts) self.layer = CacheMapLayer(self.tile_mgr, image_opts=default_image_opts) self.layer.extent = BBOXCoverage([0, 0, 90, 45], SRS(4326)).extent def test_get_outside_extent(self): assert_raises(BlankImage, self.layer.get_map, MapQuery((-180, -90, 0, 0), (300, 150), SRS(4326), 'png')) def test_get_map_small(self): result = self.layer.get_map(MapQuery((-180, -90, 180, 90), (300, 150), SRS(4326), 'png')) eq_(self.file_cache.stored_tiles, set([(1, 0, 1)])) # source requests one tile (no meta-tiling configured) eq_(self.client.requested, [((0.0, -90.0, 180.0, 90.0), (256, 256), SRS('EPSG:4326'))]) eq_(result.size, (300, 150)) def test_get_map_small_with_source_extent(self): self.source.extent = BBOXCoverage([0, 0, 90, 45], SRS(4326)).extent result = self.layer.get_map(MapQuery((-180, -90, 180, 90), (300, 150), SRS(4326), 'png')) eq_(self.file_cache.stored_tiles, set([(1, 0, 1)])) # source requests one tile (no meta-tiling configured) limited to source.extent eq_(self.client.requested, [((0, 0, 90, 45), (128, 64), (SRS(4326)))]) eq_(result.size, (300, 150))
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))
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)
def layer(self, mock_file_cache, source, tile_locker): grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90]) image_opts = ImageOptions(resampling='nearest', format='png') tile_mgr = TileManager(grid, mock_file_cache, [source], 'png', meta_size=[1, 1], meta_buffer=0, image_opts=image_opts, locker=tile_locker) layer = CacheMapLayer(tile_mgr, image_opts=default_image_opts) layer.extent = BBOXCoverage([0, 0, 90, 45], SRS(4326)).extent return layer
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)
class TestCacheMapLayer(object): 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) def test_get_map_small(self): result = self.layer.get_map(MapQuery((-180, -90, 180, 90), (300, 150), SRS(4326), 'png')) eq_(self.file_cache.stored_tiles, set([(0, 0, 1), (1, 0, 1)])) eq_(result.size, (300, 150)) def test_get_map_large(self): # gets next resolution layer result = self.layer.get_map(MapQuery((-180, -90, 180, 90), (600, 300), SRS(4326), 'png')) eq_(self.file_cache.stored_tiles, set([(0, 0, 2), (1, 0, 2), (0, 1, 2), (1, 1, 2), (2, 0, 2), (3, 0, 2), (2, 1, 2), (3, 1, 2)])) eq_(result.size, (600, 300)) def test_transformed(self): result = self.layer.get_map(MapQuery( (-20037508.34, -20037508.34, 20037508.34, 20037508.34), (500, 500), SRS(900913), 'png')) eq_(self.file_cache.stored_tiles, set([(0, 0, 2), (1, 0, 2), (0, 1, 2), (1, 1, 2), (2, 0, 2), (3, 0, 2), (2, 1, 2), (3, 1, 2)])) eq_(result.size, (500, 500)) def test_get_map_with_res_range(self): res_range = resolution_range(1000, 10) self.source = WMSSource(self.client, res_range=res_range) 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) 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))
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
def __init__(self, tile_manager, extent=None, image_opts=None, max_tile_limit=None, tiled_only=False): CacheMapLayer.__init__(self, tile_manager, extent=extent, image_opts=image_opts, max_tile_limit=max_tile_limit) self.supports_meta_tiles = not tiled_only self.tiled_only = tiled_only
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))
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)
def create_couchdb_source(layer, app_state, grid): cache = create_couchdb_cache(layer.wmts_source, app_state) source = DummySource() image_opts = image_options(layer.wmts_source) tile_mgr = create_tile_manager(format=layer.wmts_source.format, cache=cache, sources=[source], grid=grid, image_opts=image_opts) source = CacheMapLayer(tile_mgr) return source
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.source_base = MockSource() self.source_overlay = MockSource() self.image_opts = ImageOptions(format='image/png') self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source_base, self.source_overlay], 'png', image_opts=self.image_opts) self.layer = CacheMapLayer(self.tile_mgr)
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', 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
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") 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)
def get_map(self, query): if self.tiled_only: query.tiled_only = True return CacheMapLayer.get_map(self, query)
class TestCacheMapLayer(object): 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') 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) def test_get_map_small(self): result = self.layer.get_map( MapQuery((-180, -90, 180, 90), (300, 150), SRS(4326), 'png')) eq_(self.file_cache.stored_tiles, set([(0, 0, 1), (1, 0, 1)])) eq_(result.size, (300, 150)) def test_get_map_large(self): # gets next resolution layer result = self.layer.get_map( MapQuery((-180, -90, 180, 90), (600, 300), SRS(4326), 'png')) eq_( self.file_cache.stored_tiles, set([(0, 0, 2), (1, 0, 2), (0, 1, 2), (1, 1, 2), (2, 0, 2), (3, 0, 2), (2, 1, 2), (3, 1, 2)])) eq_(result.size, (600, 300)) def test_transformed(self): result = self.layer.get_map( MapQuery((-20037508.34, -20037508.34, 20037508.34, 20037508.34), (500, 500), SRS(900913), 'png')) eq_( self.file_cache.stored_tiles, set([(0, 0, 2), (1, 0, 2), (0, 1, 2), (1, 1, 2), (2, 0, 2), (3, 0, 2), (2, 1, 2), (3, 1, 2)])) eq_(result.size, (500, 500)) def test_single_tile_match(self): result = self.layer.get_map( MapQuery((0.001, 0, 90, 90), (256, 256), SRS(4326), 'png', tiled_only=True)) eq_(self.file_cache.stored_tiles, set([(3, 0, 2), (2, 0, 2), (3, 1, 2), (2, 1, 2)])) eq_(result.size, (256, 256)) @raises(MapBBOXError) def test_single_tile_no_match(self): self.layer.get_map( MapQuery((0.1, 0, 90, 90), (256, 256), SRS(4326), 'png', tiled_only=True)) 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))
class TestCacheMapLayer(object): 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") 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) def test_get_map_small(self): result = self.layer.get_map(MapQuery((-180, -90, 180, 90), (300, 150), SRS(4326), "png")) eq_(self.file_cache.stored_tiles, set([(0, 0, 1), (1, 0, 1)])) eq_(result.size, (300, 150)) def test_get_map_large(self): # gets next resolution layer result = self.layer.get_map(MapQuery((-180, -90, 180, 90), (600, 300), SRS(4326), "png")) eq_( self.file_cache.stored_tiles, set([(0, 0, 2), (1, 0, 2), (0, 1, 2), (1, 1, 2), (2, 0, 2), (3, 0, 2), (2, 1, 2), (3, 1, 2)]), ) eq_(result.size, (600, 300)) def test_transformed(self): result = self.layer.get_map( MapQuery((-20037508.34, -20037508.34, 20037508.34, 20037508.34), (500, 500), SRS(900913), "png") ) eq_( self.file_cache.stored_tiles, set([(0, 0, 2), (1, 0, 2), (0, 1, 2), (1, 1, 2), (2, 0, 2), (3, 0, 2), (2, 1, 2), (3, 1, 2)]), ) eq_(result.size, (500, 500)) def test_single_tile_match(self): result = self.layer.get_map(MapQuery((0.001, 0, 90, 90), (256, 256), SRS(4326), "png", tiled_only=True)) eq_(self.file_cache.stored_tiles, set([(3, 0, 2), (2, 0, 2), (3, 1, 2), (2, 1, 2)])) eq_(result.size, (256, 256)) @raises(MapBBOXError) def test_single_tile_no_match(self): self.layer.get_map(MapQuery((0.1, 0, 90, 90), (256, 256), SRS(4326), "png", tiled_only=True)) 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))