How to use the tilecloud.BoundingPyramid.from_string 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 / mbtiles-from-store.py View on Github external
option_parser.add_option('--format', metavar='FORMAT')
    options, args = option_parser.parse_args(argv[1:])
    assert options.store
    tile_layout = tile_layouts[options.tile_layout]()
    if options.prefix or options.suffix:
        tile_layout = WrappedTileLayout(tile_layout, options.prefix, options.suffix)
    if options.store == 'fs':
        store = FilesystemTileStore(tile_layout)
    elif options.store == 'lines':
        store = LinesTileStore(tile_layout, fileinput.input(args))
    elif options.store == 's3':
        store = S3TileStore(options.bucket_name, tile_layout)
    else:
        assert False
    if options.bounds:
        bounds = BoundingPyramid.from_string(options.bounds)
        tilestream = BoundingPyramidTileStore(bounds).list()
        tilestream = store.get(tilestream)
    else:
        tilestream = store.get_all()
    connection = sqlite3.connect(options.output)
    kwargs = {}
    mbtiles_tile_store = MBTilesTileStore(connection, commit=False)
    for key in 'name type version description format'.split():
        value = getattr(options, key)
        if value is not None:
            mbtiles_tile_store.metadata[key] = getattr(options, key)
    tilestream = mbtiles_tile_store.put(tilestream)
    consume(tilestream, options.limit)
    connection.commit()
github camptocamp / tilecloud / examples / download.py View on Github external
def main():
    # Create our input and output TileStores
    input_tilestore = TileStore.load("tiles.openstreetmap_org")
    output_tilestore = TileStore.load("local.mbtiles")
    # 1. Generate a list of tiles to download from a BoundingPyramid
    #    4/8/5 is the root tile, corresponding to Central Europe
    #    +3/+1/+1 specifies up to zoom level 4 + 3 = 7 and an extent of one tile in the X and Y directions
    bounding_pyramid = BoundingPyramid.from_string("4/8/5:+3/+1/+1")
    bounding_pyramid_tilestore = BoundingPyramidTileStore(bounding_pyramid)
    tilestream = bounding_pyramid_tilestore.list()
    # 2. Filter out tiles that already downloaded
    tilestream = (tile for tile in tilestream if tile not in output_tilestore)
    # 3. Get the tile from openstreetmap.org
    tilestream = input_tilestore.get(tilestream)
    # 4. Save the tile to local.mbtiles
    tilestream = output_tilestore.put(tilestream)
    # 5. Log the fact that the tile was downloaded
    tilestream = imap(Logger(logger, logging.INFO, "downloaded %(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)