Пример #1
0
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))
Пример #2
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)
Пример #3
0
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))
Пример #4
0
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))
Пример #5
0
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))
Пример #6
0
 def get_map(self, query):
     if self.tiled_only:
         query.tiled_only = True
     return CacheMapLayer.get_map(self, query)
Пример #7
0
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))
Пример #8
0
 def get_map(self, query):
     if self.tiled_only:
         query.tiled_only = True
     return CacheMapLayer.get_map(self, query)