Exemplo n.º 1
0
class TestWMTSTileLayout(unittest.TestCase):

    def setUp(self):
        self.rest = WMTSTileLayout(
                url='test',
                layer='layer',
                style='default',
                format='.png',
                dimensions=(('DATE', '2011'),),
                tile_matrix_set='swissgrid',
                request_encoding='REST',
        )
        self.kvp = WMTSTileLayout(
                url='test',
                layer='layer',
                style='default',
                format='.png',
                dimensions=(('DATE', '2011'),),
                tile_matrix_set='swissgrid',
                request_encoding='KVP',
        )

    def test_filename(self):
        self.assertEqual(self.rest.filename(TileCoord(1, 2, 3)), 'test/1.0.0/layer/default/2011/swissgrid/1/3/2.png')
        self.assertEqual(self.kvp.filename(TileCoord(1, 2, 3)), 'test?Service=WMTS&Request=GetTile&Format=.png&Version=1.0.0&Layer=layer&Style=default&DATE=2011&TileMatrixSet=swissgrid&TileMatrix=1&TileRow=3&TileCol=2')
Exemplo n.º 2
0
class TestWMTSTileLayout(unittest.TestCase):
    def setUp(self):
        self.rest = WMTSTileLayout(
            url="test",
            layer="layer",
            style="default",
            format=".png",
            dimensions_name=("DATE", ),
            tile_matrix_set="swissgrid",
            request_encoding="REST",
        )
        self.kvp = WMTSTileLayout(
            url="test",
            layer="layer",
            style="default",
            format=".png",
            dimensions_name=("DATE", ),
            tile_matrix_set="swissgrid",
            request_encoding="KVP",
        )
        self.rest_nourl = WMTSTileLayout(
            layer="layer",
            style="default",
            format=".png",
            dimensions_name=("DATE", ),
            tile_matrix_set="swissgrid",
            request_encoding="REST",
        )
        self.kvp_nourl = WMTSTileLayout(
            layer="layer",
            style="default",
            format=".png",
            dimensions_name=("DATE", ),
            tile_matrix_set="swissgrid",
            request_encoding="KVP",
        )

    def test_filename(self):
        assert (self.rest.filename(
            TileCoord(1, 2, 3),
            {"dimension_DATE": "2011"
             }) == "test/1.0.0/layer/default/2011/swissgrid/1/3/2.png")
        assert (
            self.kvp.filename(TileCoord(1, 2, 3),
                              {"dimension_DATE": "2011"}) ==
            "test?Service=WMTS&Request=GetTile&Format=.png&Version=1.0.0&Layer=layer&Style=default&DATE=2011&TileMatrixSet=swissgrid&TileMatrix=1&TileRow=3&TileCol=2"
        )

    def test_filename_without_url(self):
        # s3 url it shouldn't starts with a /
        assert (self.rest_nourl.filename(TileCoord(
            1, 2, 3), {"dimension_DATE": "2011"
                       }) == "1.0.0/layer/default/2011/swissgrid/1/3/2.png")
        assert (
            self.kvp_nourl.filename(TileCoord(1, 2, 3),
                                    {"dimension_DATE": "2011"}) ==
            "?Service=WMTS&Request=GetTile&Format=.png&Version=1.0.0&Layer=layer&Style=default&DATE=2011&TileMatrixSet=swissgrid&TileMatrix=1&TileRow=3&TileCol=2"
        )
Exemplo n.º 3
0
class TestWMTSTileLayout(unittest.TestCase):
    def setUp(self):
        self.rest = WMTSTileLayout(url='test',
                                   layer='layer',
                                   style='default',
                                   format='.png',
                                   dimensions_name=('DATE', ),
                                   tile_matrix_set='swissgrid',
                                   request_encoding='REST')
        self.kvp = WMTSTileLayout(url='test',
                                  layer='layer',
                                  style='default',
                                  format='.png',
                                  dimensions_name=('DATE', ),
                                  tile_matrix_set='swissgrid',
                                  request_encoding='KVP')
        self.rest_nourl = WMTSTileLayout(layer='layer',
                                         style='default',
                                         format='.png',
                                         dimensions_name=('DATE', ),
                                         tile_matrix_set='swissgrid',
                                         request_encoding='REST')
        self.kvp_nourl = WMTSTileLayout(layer='layer',
                                        style='default',
                                        format='.png',
                                        dimensions_name=('DATE', ),
                                        tile_matrix_set='swissgrid',
                                        request_encoding='KVP')

    def test_filename(self):
        self.assertEqual(
            self.rest.filename(TileCoord(1, 2, 3), {'dimension_DATE': '2011'}),
            'test/1.0.0/layer/default/2011/swissgrid/1/3/2.png')
        self.assertEqual(
            self.kvp.filename(TileCoord(1, 2, 3), {'dimension_DATE': '2011'}),
            'test?Service=WMTS&Request=GetTile&Format=.png&Version=1.0.0&Layer=layer&Style=default&DATE=2011&TileMatrixSet=swissgrid&TileMatrix=1&TileRow=3&TileCol=2'
        )

    def test_filename_without_url(self):
        # s3 url it shouldn't starts with a /
        self.assertEqual(
            self.rest_nourl.filename(TileCoord(1, 2, 3),
                                     {'dimension_DATE': '2011'}),
            '1.0.0/layer/default/2011/swissgrid/1/3/2.png')
        self.assertEqual(
            self.kvp_nourl.filename(TileCoord(1, 2, 3),
                                    {'dimension_DATE': '2011'}),
            '?Service=WMTS&Request=GetTile&Format=.png&Version=1.0.0&Layer=layer&Style=default&DATE=2011&TileMatrixSet=swissgrid&TileMatrix=1&TileRow=3&TileCol=2'
        )
Exemplo n.º 4
0
class TestWMTSTileLayout(unittest.TestCase):

    def setUp(self):
        self.rest = WMTSTileLayout(
            url='test',
            layer='layer',
            style='default',
            format='.png',
            dimensions_name=('DATE',),
            tile_matrix_set='swissgrid',
            request_encoding='REST')
        self.kvp = WMTSTileLayout(
            url='test',
            layer='layer',
            style='default',
            format='.png',
            dimensions_name=('DATE',),
            tile_matrix_set='swissgrid',
            request_encoding='KVP')
        self.rest_nourl = WMTSTileLayout(
            layer='layer',
            style='default',
            format='.png',
            dimensions_name=('DATE',),
            tile_matrix_set='swissgrid',
            request_encoding='REST')
        self.kvp_nourl = WMTSTileLayout(
            layer='layer',
            style='default',
            format='.png',
            dimensions_name=('DATE',),
            tile_matrix_set='swissgrid',
            request_encoding='KVP')

    def test_filename(self):
        assert self.rest.filename(TileCoord(1, 2, 3), {'dimension_DATE': '2011'}) == 'test/1.0.0/layer/default/2011/swissgrid/1/3/2.png'
        assert self.kvp.filename(TileCoord(1, 2, 3), {'dimension_DATE': '2011'}) == 'test?Service=WMTS&Request=GetTile&Format=.png&Version=1.0.0&Layer=layer&Style=default&DATE=2011&TileMatrixSet=swissgrid&TileMatrix=1&TileRow=3&TileCol=2'

    def test_filename_without_url(self):
        # s3 url it shouldn't starts with a /
        assert self.rest_nourl.filename(TileCoord(1, 2, 3), {'dimension_DATE': '2011'}) == '1.0.0/layer/default/2011/swissgrid/1/3/2.png'
        assert self.kvp_nourl.filename(TileCoord(1, 2, 3), {'dimension_DATE': '2011'}) == '?Service=WMTS&Request=GetTile&Format=.png&Version=1.0.0&Layer=layer&Style=default&DATE=2011&TileMatrixSet=swissgrid&TileMatrix=1&TileRow=3&TileCol=2'
Exemplo n.º 5
0
    def get_store(self, cache, layer, read_only=False):
        grid = layer['grid_ref'] if 'grid_ref' in layer else None
        layout = WMTSTileLayout(
            layer=layer['name'],
            url=cache['folder'],
            style=layer['wmts_style'],
            format='.' + layer['extension'],
            dimensions_name=[
                dimension['name'] for dimension in layer['dimensions']
            ],
            tile_matrix_set=layer['grid'],
            tile_matrix=lambda z: get_tile_matrix_identifier(grid, zoom=z),
            request_encoding='REST',
        )
        # store
        if cache['type'] == 's3':
            # on s3
            cache_tilestore = S3TileStore(
                cache['bucket'],
                layout,
                s3_host=cache.get('host'),
                cache_control=cache.get('cache_control'))  # pragma: no cover
        elif cache['type'] == 'mbtiles':
            metadata = {}
            for dimension in layer['dimensions']:
                metadata['dimension_' +
                         dimension['name']] = dimension['default']
            # on mbtiles file
            filename = layout.filename(TileCoord(
                0, 0, 0), metadata=metadata).replace('/0/0/0', '') + '.mbtiles'
            if not os.path.exists(os.path.dirname(filename)):
                os.makedirs(os.path.dirname(filename))
            cache_tilestore = MBTilesTileStore(
                sqlite3.connect(filename),
                content_type=layer['mime_type'],
                tilecoord_in_topleft=True,
            )
        elif cache['type'] == 'bsddb':
            metadata = {}
            for dimension in layer['dimensions']:
                metadata['dimension_' +
                         dimension['name']] = dimension['default']
            import bsddb3 as bsddb
            from tilecloud.store.bsddb import BSDDBTileStore

            # on bsddb file
            filename = layout.filename(TileCoord(
                0, 0, 0), metadata=metadata).replace('/0/0/0', '') + '.bsddb'
            if not os.path.exists(os.path.dirname(filename)):
                os.makedirs(os.path.dirname(filename))
            db = bsddb.hashopen(
                filename,
                # and os.path.exists(filename) to avoid error on non existing file
                'r' if read_only and os.path.exists(filename) else 'c')

            class Close:
                def __init__(self, db):
                    self.db = db

                def __call__(self):
                    self.db.close()

            self._close_actions.append(Close(db))

            cache_tilestore = BSDDBTileStore(
                db,
                content_type=layer['mime_type'],
            )
        elif cache['type'] == 'filesystem':
            # on filesystem
            cache_tilestore = FilesystemTileStore(
                layout,
                content_type=layer['mime_type'],
            )
        else:
            exit('unknown cache type: ' + cache['type'])  # pragma: no cover

        return cache_tilestore
Exemplo n.º 6
0
    def get_store(self, cache, layer, read_only=False):
        grid = layer['grid_ref'] if 'grid_ref' in layer else None
        layout = WMTSTileLayout(
            layer=layer['name'],
            url=cache['folder'],
            style=layer['wmts_style'],
            format='.' + layer['extension'],
            dimensions_name=[dimension['name'] for dimension in layer['dimensions']],
            tile_matrix_set=layer['grid'],
            tile_matrix=lambda z: get_tile_matrix_identifier(grid, zoom=z),
            request_encoding='REST',
        )
        # store
        if cache['type'] == 's3':
            # on s3
            cache_tilestore = S3TileStore(
                cache['bucket'], layout,
                s3_host=cache.get('host'),
                cache_control=cache.get('cache_control'))  # pragma: no cover
        elif cache['type'] == 'mbtiles':
            metadata = {}
            for dimension in layer['dimensions']:
                metadata['dimension_' + dimension['name']] = dimension['default']
            # on mbtiles file
            filename = layout.filename(
                TileCoord(0, 0, 0), metadata=metadata
            ).replace('/0/0/0', '') + '.mbtiles'
            if not os.path.exists(os.path.dirname(filename)):
                os.makedirs(os.path.dirname(filename))
            cache_tilestore = MBTilesTileStore(
                sqlite3.connect(filename),
                content_type=layer['mime_type'],
                tilecoord_in_topleft=True,
            )
        elif cache['type'] == 'bsddb':
            metadata = {}
            for dimension in layer['dimensions']:
                metadata['dimension_' + dimension['name']] = dimension['default']
            import bsddb3 as bsddb
            from tilecloud.store.bsddb import BSDDBTileStore

            # on bsddb file
            filename = layout.filename(
                TileCoord(0, 0, 0), metadata=metadata
            ).replace('/0/0/0', '') + '.bsddb'
            if not os.path.exists(os.path.dirname(filename)):
                os.makedirs(os.path.dirname(filename))
            db = bsddb.hashopen(
                filename,
                # and os.path.exists(filename) to avoid error on non existing file
                'r' if read_only and os.path.exists(filename) else 'c'
            )

            class Close:
                def __init__(self, db):
                    self.db = db

                def __call__(self):
                    self.db.close()

            self._close_actions.append(Close(db))

            cache_tilestore = BSDDBTileStore(
                db, content_type=layer['mime_type'],
            )
        elif cache['type'] == 'filesystem':
            # on filesystem
            cache_tilestore = FilesystemTileStore(
                layout,
                content_type=layer['mime_type'],
            )
        else:
            exit('unknown cache type: ' + cache['type'])  # pragma: no cover

        return cache_tilestore