How to use the tilecloud.store.mbtiles.MBTilesTileStore function in tilecloud

To help you get started, we’ve selected a few tilecloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github camptocamp / tilecloud / tilecloud / __init__.py View on Github external
return SQSTileStore(queue)
        if name.startswith("redis://"):
            from tilecloud.store.redis import RedisTileStore

            return RedisTileStore(name)
        _, ext = os.path.splitext(name)
        if ext == ".bsddb":
            import bsddb  # pylint: disable=import-error
            from tilecloud.store.bsddb import BSDDBTileStore

            return BSDDBTileStore(bsddb.hashopen(name))
        if ext == ".mbtiles":
            import sqlite3
            from tilecloud.store.mbtiles import MBTilesTileStore

            return MBTilesTileStore(sqlite3.connect(name))
        if ext == ".zip":
            import zipfile
            from tilecloud.store.zip import ZipTileStore

            return ZipTileStore(zipfile.ZipFile(name, "a"))
        module = __import__(name)
        components = name.split(".")
        module = reduce(getattr, components[1:], module)
        return getattr(module, "tilestore")
github camptocamp / tilecloud / examples / renderingtheworld.py View on Github external
url="http://v2.suite.opengeo.org/geoserver/gwc/service/wmts/",
        layer="medford:buildings",
        style="_null",
        format="image/png",
        tile_matrix_set="EPSG:900913",
        tile_matrix=lambda z: "EPSG:900913:{0:d}".format(z),
    )
    tilestream = generate_tilestore.get(tilestream)
    tilestream = imap(Logger(logger, logging.INFO, "got %(tilecoord)s, error=%(error)s"), tilestream)
    # Put the tile back into the RenderingTheWorld tile store.  This check whether the tile should be
    # subdivided, and, if so, adds the tile's children to the list of tiles to be generated.
    tilestream = rendering_the_world_tilestore.put(tilestream)
    # Get rid of tiles that returned an error (i.e. where there was no data).
    tilestream = imap(DropErrors(), tilestream)
    # Store the generated tiles in the output tile store, in our case a local MBTiles file.
    output_tilestore = MBTilesTileStore(sqlite3.connect("medford_buildings.mbtiles"))
    tilestream = output_tilestore.put(tilestream)
    tilestream = imap(Logger(logger, logging.INFO, "saved %(tilecoord)s"), tilestream)
    # Go!
    consume(tilestream, None)
github camptocamp / tilecloud / openwebglobe.py View on Github external
def main(argv):
    logging.basicConfig(format='%(asctime)s:%(levelname)s:%(module)s:%(message)s', level=logging.INFO)
    bounding_pyramid = BoundingPyramid.from_string('19/269628/181744:278856/187776')
    bounding_pyramid_tile_store = BoundingPyramidTileStore(bounding_pyramid)
    tilestream = bounding_pyramid_tile_store.list()
    shutil.copyfile('map3d.done.mbtiles', 'map3d.done.mbtiles.tmp')
    tmp_done_tile_store = MBTilesTileStore(sqlite3.connect('map3d.done.mbtiles.tmp', check_same_thread=False))
    tilestream = (tile for tile in tilestream if tile not in tmp_done_tile_store)
    pool = multiprocessing.Pool(6)
    tilestream = pool.imap_unordered(convert_to_jpeg_and_put_if_not_transparent, tilestream)
    tilestream = imap(Logger(logger, logging.INFO, 'wrote %(tilecoord)s'), tilestream)
    done_tile_store = MBTilesTileStore(sqlite3.connect('map3d.done.mbtiles'))
    tilestream = done_tile_store.put(tilestream)
    consume(tilestream, None)
github camptocamp / tilecloud / openwebglobe.py View on Github external
def main(argv):
    logging.basicConfig(format='%(asctime)s:%(levelname)s:%(module)s:%(message)s', level=logging.INFO)
    bounding_pyramid = BoundingPyramid.from_string('19/269628/181744:278856/187776')
    bounding_pyramid_tile_store = BoundingPyramidTileStore(bounding_pyramid)
    tilestream = bounding_pyramid_tile_store.list()
    shutil.copyfile('map3d.done.mbtiles', 'map3d.done.mbtiles.tmp')
    tmp_done_tile_store = MBTilesTileStore(sqlite3.connect('map3d.done.mbtiles.tmp', check_same_thread=False))
    tilestream = (tile for tile in tilestream if tile not in tmp_done_tile_store)
    pool = multiprocessing.Pool(6)
    tilestream = pool.imap_unordered(convert_to_jpeg_and_put_if_not_transparent, tilestream)
    tilestream = imap(Logger(logger, logging.INFO, 'wrote %(tilecoord)s'), tilestream)
    done_tile_store = MBTilesTileStore(sqlite3.connect('map3d.done.mbtiles'))
    tilestream = done_tile_store.put(tilestream)
    consume(tilestream, None)
github camptocamp / tilecloud-chain / tilecloud_chain / __init__.py View on Github external
# 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)):