Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fillup(self, top=0):
for z in xrange(max(self.bounds), top, -1):
xbounds, ybounds = self.bounds[z]
self.add(TileCoord(z - 1, xbounds.start // 2, ybounds.start // 2))
self.add(TileCoord(z - 1, xbounds.stop // 2, ybounds.stop // 2))
def fill_up(z, bounds):
assert z > 0
xbounds, ybounds = bounds
return (
Bounds(xbounds.start // 2, max(xbounds.stop // 2, 1)),
Bounds(ybounds.start // 2, max(ybounds.stop // 2, 1)),
)
def metatilecoord(self, n=8):
return TileCoord(self.z, n * (self.x // n), n * (self.y // n), n)
return
line = line.split('#')[0].strip()
if line != '':
try:
tilecoord = parse_tilecoord(line)
except ValueError as e: # pragma: no cover
logger.error("A tile '{}' is not in the format 'z/x/y' or z/x/y:+n/+n\n{}".format(
line, repr(e), exc_info=True)
)
continue
for dimensions in self.all_dimensions:
metadata = {'layer': self.layer}
for k, v in dimensions.items():
metadata["dimension_" + k] = v
yield Tile(tilecoord, metadata=metadata)
if self._options.role in ('local', 'master') and 'logging' in self._gene.config:
self._gene.imap(DatabaseLoggerInit(
self._gene.config['logging'],
self._options is not None and self._options.daemon,
))
if self._options.local_process_number is not None: # pragma: no cover
self._gene.add_local_process_filter()
elif self._options.role == 'hash':
try:
z, x, y = (int(v) for v in self._options.get_hash.split('/'))
if layer.get('meta'):
self._gene.set_tilecoords([TileCoord(z, x, y, layer['meta_size'])], layer)
else:
self._gene.set_tilecoords([TileCoord(z, x, y)], layer)
except ValueError as e: # pragma: no cover
exit(
"Tile '{}' is not in the format 'z/x/y'\n{}".format(
self._options.get_hash, repr(e))
)
# At this stage, the tilestream contains metatiles that intersect geometry
self._gene.add_logger()
self._count_metatiles = self._gene.counter()
if self._options.role == 'master': # pragma: no cover
# Put the metatiles into the SQS or Redis queue
self._gene.put(self._queue_tilestore)
self._count_tiles = self._gene.counter()
def list(self):
bbox = self.geom.bounds
bounds = {}
for zoom in range(0, len(self.metatile_configuration.resolutions)):
x_bounds = Bounds(self.unit_to_metatile(bbox[0], zoom, self.metatile_configuration.max_extent[0]),
self.unit_to_metatile(bbox[2], zoom, self.metatile_configuration.max_extent[0]) + 1)
y_bounds = Bounds(self.unit_to_metatile(bbox[1], zoom, self.metatile_configuration.max_extent[1]),
self.unit_to_metatile(bbox[3], zoom, self.metatile_configuration.max_extent[1]) + 1)
bounds[zoom] = (x_bounds, y_bounds)
bounding_pyramid = BoundingPyramid(bounds)
for tilecoord in bounding_pyramid:
zoom, meta_x, meta_y = tilecoord.z, tilecoord.x, tilecoord.y
for x in range(meta_x * self.metatile_configuration.size,
meta_x * self.metatile_configuration.size + self.metatile_configuration.size):
for y in range(meta_y * self.metatile_configuration.size,
meta_y * self.metatile_configuration.size + self.metatile_configuration.size):
extent = loads_wkt(self.polygon((
self.tile_to_unit(x, zoom, self.metatile_configuration.max_extent[0]),
self.tile_to_unit(y, zoom, self.metatile_configuration.max_extent[1]),
self.tile_to_unit(x + 1, zoom, self.metatile_configuration.max_extent[0]),
self.tile_to_unit(y + 1, zoom, self.metatile_configuration.max_extent[1])
)))
def _get_tilestore_for_layer(self, layer):
if layer['type'] == 'wms':
params = layer['params'].copy()
if 'STYLES' not in params:
params['STYLES'] = ','.join(layer['wmts_style'] for l in layer['layers'].split(','))
if layer['generate_salt']:
params['SALT'] = str(random.randint(0, 999999))
# Get the metatile image from the WMS server
return URLTileStore(
tilelayouts=(WMSTileLayout(
url=layer['url'],
layers=layer['layers'],
srs=layer['grid_ref']['srs'],
format=layer['mime_type'],
border=layer['meta_buffer'] if layer.get('meta', False) else 0,
tilegrid=self._gene.get_grid(layer)['obj'],
params=params,
),),
headers=layer['headers'],
)
elif layer['type'] == 'mapnik': # pragma: no cover
try:
from tilecloud.store.mapnik_ import MapnikTileStore
from tilecloud_chain.mapnik_ import MapnikDropActionTileStore
except ImportError:
return NullTileStore()
if name.startswith("bounds://"):
from tilecloud.store.boundingpyramid import BoundingPyramidTileStore
return BoundingPyramidTileStore(BoundingPyramid.from_string(name[9:]))
if name.startswith("file://"):
from tilecloud.layout.template import TemplateTileLayout
from tilecloud.store.filesystem import FilesystemTileStore
return FilesystemTileStore(TemplateTileLayout(name[7:]),)
if name.startswith("http://") or name.startswith("https://"):
from tilecloud.layout.template import TemplateTileLayout
from tilecloud.store.url import URLTileStore
return URLTileStore((TemplateTileLayout(name),))
if name.startswith("memcached://"):
from tilecloud.layout.template import TemplateTileLayout
from tilecloud.store.memcached import MemcachedTileStore
from tilecloud.lib.memcached import MemcachedClient
server, template = name[12:].split("/", 1)
host, port = server.split(":", 1)
client = MemcachedClient(host, int(port))
return MemcachedTileStore(client, TemplateTileLayout(template))
if name.startswith("s3://"):
from tilecloud.layout.template import TemplateTileLayout
from tilecloud.store.s3 import S3TileStore
bucket, template = name[5:].split("/", 1)
return S3TileStore(bucket, TemplateTileLayout(template))
if name.startswith("sqs://"):
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()
def list(self):
bbox = self.geom.bounds
bounds = {}
for zoom in range(0, len(self.metatile_configuration.resolutions)):
x_bounds = Bounds(self.unit_to_metatile(bbox[0], zoom, self.metatile_configuration.max_extent[0]),
self.unit_to_metatile(bbox[2], zoom, self.metatile_configuration.max_extent[0]) + 1)
y_bounds = Bounds(self.unit_to_metatile(bbox[1], zoom, self.metatile_configuration.max_extent[1]),
self.unit_to_metatile(bbox[3], zoom, self.metatile_configuration.max_extent[1]) + 1)
bounds[zoom] = (x_bounds, y_bounds)
bounding_pyramid = BoundingPyramid(bounds)
for tilecoord in bounding_pyramid:
zoom, meta_x, meta_y = tilecoord.z, tilecoord.x, tilecoord.y
for x in range(meta_x * self.metatile_configuration.size,
meta_x * self.metatile_configuration.size + self.metatile_configuration.size):
for y in range(meta_y * self.metatile_configuration.size,
meta_y * self.metatile_configuration.size + self.metatile_configuration.size):
extent = loads_wkt(self.polygon((
self.tile_to_unit(x, zoom, self.metatile_configuration.max_extent[0]),
self.tile_to_unit(y, zoom, self.metatile_configuration.max_extent[1]),
self.tile_to_unit(x + 1, zoom, self.metatile_configuration.max_extent[0]),
self.tile_to_unit(y + 1, zoom, self.metatile_configuration.max_extent[1])
)))
tile = Tile(TileCoord(zoom, x, y), meta=tilecoord)
if extent.intersects(self.geom):
yield self.get_one(tile)