def __init__(self, bucket, tilelayout, dry_run=False, s3_host=None, cache_control=None, **kwargs): self.client = get_client(s3_host) self.bucket = bucket self.tilelayout = tilelayout self.dry_run = dry_run self.cache_control = cache_control TileStore.__init__(self, **kwargs)
def __init__(self, connection, commit=True, **kwargs): self.connection = connection self.metadata = Metadata(self.connection, commit) self.tiles = Tiles(self.connection, commit) if "content_type" not in kwargs and "format" in self.metadata: kwargs["content_type"] = mimetypes.types_map.get("." + self.metadata["format"], None) TileStore.__init__(self, **kwargs)
def __init__(self, connection, commit=True, tilecoord_in_topleft=False, **kwargs): self.connection = connection self.metadata = Metadata(self.connection, commit) self.tiles = Tiles(tilecoord_in_topleft, self.connection, commit) if 'content_type' not in kwargs and 'format' in self.metadata: kwargs['content_type'] = mimetypes.types_map.get('.' + self.metadata['format']) TileStore.__init__(self, **kwargs)
def __init__( self, tilegrid, mapfile, data_buffer=128, image_buffer=0, output_format='png256', resolution=2, layers_fields={}, drop_empty_utfgrid=False, proj4_literal=None, **kwargs): """ Constructs a MapnikTileStore :param tilegrid: the tilegrid. :param mapfile: the file used to render the tiles. :param buffer_size: the image buffer size default is 128. :param output_format: the output format, possible values 'jpeg', 'png', 'png256', 'grid', default is 'png256' :param layers: the layers and fields used in the grid generation, example: { 'my_layer': ['my_first_field', 'my_segonf_field']}, default is {}. :param **kwargs: for extended class. """ TileStore.__init__(self, **kwargs) self.tilegrid = tilegrid self.buffer = image_buffer self.output_format = output_format self.resolution = resolution self.layers_fields = layers_fields self.drop_empty_utfgrid = drop_empty_utfgrid self.mapnik = mapnik.Map(tilegrid.tile_size, tilegrid.tile_size) mapnik.load_map(self.mapnik, mapfile, True) self.mapnik.buffer_size = data_buffer if proj4_literal is not None: self.mapnik.srs = proj4_literal
def __init__(self, zipfile, layout=None, **kwargs): TileStore.__init__(self, **kwargs) self.zipfile = zipfile self.layout = layout if self.layout is None: extension_count = defaultdict(int) for name in self.zipfile.namelist(): extension_count[os.path.splitext(name)[1]] += 1 for extension, count in sorted(extension_count.items(), key=lambda p: tuple(reversed(p)), reverse=True): if re.match(r"\.(jpe?g|png)\Z", extension, re.I): self.layout = WrappedTileLayout(OSMTileLayout(), suffix=extension) break if self.layout is None: self.layout = OSMTileLayout()
def __init__(self, z, bounds, file=None, **kwargs): TileStore.__init__(self, **kwargs) self.z = z self.xbounds, self.ybounds = bounds self.width = self.xbounds.stop - self.xbounds.start self.height = self.ybounds.stop - self.ybounds.start if 'bounding_pyramid' not in kwargs: self.bounding_pyramid = BoundingPyramid({self.z: (self.xbounds, self.ybounds)}) if file: self.image = PIL.Image.open(file) assert self.image.mode == '1' assert self.image.size == (self.width, self.height) else: self.image = PIL.Image.new('1', (self.width, self.height)) self.pixels = self.image.load()
def main(argv): # 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 not tile 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)
def test_empty(self): ts = TileStore() self.assertEqual(ts.bounding_pyramid, None) self.assertEqual(ts.content_type, None) self.assertEqual(len(ts), 0) self.assertRaises(NotImplementedError, next, ts.delete((Tile(TileCoord(0, 0, 0)),))) self.assertRaises(NotImplementedError, ts.delete_one, None) self.assertEqual(ts.get_cheap_bounding_pyramid(), None) self.assertRaises(NotImplementedError, next, ts.get((Tile(TileCoord(0, 0, 0)),))) self.assertEqual(list(ts.get_all()), []) self.assertRaises(NotImplementedError, ts.get_one, None) self.assertEqual(list(ts.list()), []) self.assertRaises(NotImplementedError, next, ts.put((Tile(TileCoord(0, 0, 0)),))) self.assertRaises(NotImplementedError, ts.put_one, None) self.assertFalse(None in ts) self.assertEqual(ts.get_bounding_pyramid(), BoundingPyramid())
def __init__(self, db, **kwargs): self.db = db TileStore.__init__(self, **kwargs)
def __init__(self, tilelayouts, headers=None, **kwargs): TileStore.__init__(self, **kwargs) self.tilelayouts = tuple(tilelayouts) self.headers = headers or {}
def __init__(self, tile_stores, **kwargs): TileStore.__init__(self, **kwargs) self.tile_stores = tile_stores
def __init__(self, tilestores, **kwargs): TileStore.__init__(self, **kwargs) self.tilestores = tilestores
def __init__(self, tilelayout, **kwargs): TileStore.__init__(self, **kwargs) self.tilelayout = tilelayout
def __init__(self, tiles=None, **kwargs): self.tiles = tiles or {} TileStore.__init__(self, **kwargs)
def test_init_boundingpyramid(self): ts = TileStore(bounding_pyramid=BoundingPyramid.from_string('1/0/0:1/1')) self.assertTrue(Tile(TileCoord(1, 0, 0)) in ts) tiles = list(ts.list()) self.assertEqual(len(tiles), 1) self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
def test_load_https(self): from tilecloud.store.url import URLTileStore self.assertTrue(isinstance(TileStore.load('https://'), URLTileStore))
def __init__(self, tilelayouts, headers=None, **kwargs): TileStore.__init__(self, **kwargs) self.tilelayouts = tuple(tilelayouts) self.session = requests.session() if headers is not None: self.session.headers.update(headers)
def __init__(self, bounding_pyramid=None, **kwargs): TileStore.__init__(self, **kwargs) self.bounding_pyramid = bounding_pyramid or BoundingPyramid()
def __init__(self, tilelayout, file=None, **kwargs): TileStore.__init__(self, **kwargs) self.tilelayout = tilelayout self.file = file
def __init__(self, color=(0, 0, 0), transparent=True, **kwargs): TileStore.__init__(self, content_type='image/png', **kwargs) self.color = color self.inverse_color = tuple(1.0 - x for x in color) self.transparent = transparent
def __init__(self, color=(0, 0, 0), **kwargs): TileStore.__init__(self, content_type='image/png', **kwargs) self.color = color
def __init__(self, format, tile_size=256, border=0, **kwargs): self.format = format self.tile_size = tile_size self.border = border TileStore.__init__(self, **kwargs)
def __init__(self, tile_layout, lines=None, **kwargs): TileStore.__init__(self, **kwargs) self.tile_layout = tile_layout self.lines = lines
def __init__(self, bucket, tile_layout, dry_run=False, **kwargs): self.s3bucket = S3Connection().bucket(bucket) self.tile_layout = tile_layout self.dry_run = dry_run TileStore.__init__(self, **kwargs)
def __init__(self, stores, default_layer_name=None, **kwargs): TileStore.__init__(self, **kwargs) self._stores = stores self._default_store = self._stores.get(default_layer_name)
def __init__(self, queue, on_empty=maybe_stop, **kwargs): TileStore.__init__(self, **kwargs) self.queue = queue self.on_empty = maybe_stop
def __init__(self, tilestore, filters, **kwargs): TileStore.__init__(self, **kwargs) self.tilestore = tilestore self.filters = filters
def __init__(self, tilelayout, **kwargs): TileStore.__init__(self, **kwargs) assert tilelayout is not None self.tilelayout = tilelayout
def test_load_null(self): self.assertTrue(isinstance(TileStore.load('null://'), NullTileStore))
def __init__(self, client, tilelayout, flags=0, exptime=0, **kwargs): TileStore.__init__(self, **kwargs) self.client = client self.tilelayout = tilelayout self.flags = flags self.exptime = exptime
def test_load_s3(self): from tilecloud.store.s3 import S3TileStore self.assertTrue(isinstance(TileStore.load('s3://bucket/template'), S3TileStore))