Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def main():
# Create our RenderingTheWorld tile store that will manage the queue and subdivision.
# We pass it the function that decides whether a tile should be subdivided, and an initial tile.
rendering_the_world_tilestore = RenderingTheWorldTileStore(subdivide, seeds=(Tile(TileCoord(0, 0, 0)),))
# Start the tilestream by getting a list of all tiles to be generated.
tilestream = rendering_the_world_tilestore.list()
tilestream = imap(Logger(logger, logging.INFO, "get %(tilecoord)s"), tilestream)
# Create the tile store that will generate our tiles, in this case it's a demo WMTS server at OpenGeo.
# Getting tiles from this store will either return the tile as a PNG file, or set an error on the tile
# if there are no features in this tile.
generate_tilestore = WMTSTileStore(
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)
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)
queue_store=self._queue_tilestore,
count=self._count_metatiles_dropped,
)
if droppers:
self._gene.imap(MultiAction(droppers))
def add_elapsed_togenerate(metatile):
if metatile is not None:
metatile.elapsed_togenerate = metatile.tilecoord.n ** 2
return True
return False # pragma: no cover
self._gene.ifilter(add_elapsed_togenerate)
# Split the metatile image into individual tiles
self._gene.add_metatile_splitter()
self._gene.imap(Logger(logger, logging.INFO, '%(tilecoord)s, %(formated_metadata)s'))
self._gene.imap(self._count_tiles)
self._gene.process(key='pre_hash_post_process')
if self._options.role == 'hash':
self._gene.imap(HashLogger('empty_tile_detection'))
elif not self._options.near:
droppers = {}
for lname, layer in self._gene.layers.items():
if 'empty_tile_detection' in layer:
empty_tile = layer['empty_tile_detection']
droppers[lname] = HashDropper(
empty_tile['size'], empty_tile['hash'], store=self._cache_tilestore,
queue_store=self._queue_tilestore,
count=self._count_tiles_dropped,
def add_logger(self):
if not self.options.quiet and \
not self.options.verbose and \
not self.options.debug and \
os.environ.get('FRONTEND') != 'noninteractive':
def log_tiles(tile):
variables = dict()
variables.update(tile.__dict__)
variables.update(tile.tilecoord.__dict__)
sys.stdout.write("{tilecoord} {metadata} \r".format(**variables))
sys.stdout.flush()
return tile
self.imap(log_tiles)
elif not self.options.quiet:
self.imap(Logger(logger, logging.INFO, '%(tilecoord)s, %(formated_metadata)s'))
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)
def __call__(self, tile):
if tile and tile.error:
Logger.__call__(self, tile)
return tile
# Start the tilestream by getting a list of all tiles to be generated.
tilestream = rendering_the_world_tilestore.list()
tilestream = imap(Logger(logger, logging.INFO, "get %(tilecoord)s"), tilestream)
# Create the tile store that will generate our tiles, in this case it's a demo WMTS server at OpenGeo.
# Getting tiles from this store will either return the tile as a PNG file, or set an error on the tile
# if there are no features in this tile.
generate_tilestore = WMTSTileStore(
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)