Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
    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
Example #5
0
 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()
Example #6
0
 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()
Example #7
0
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)
Example #8
0
 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())
Example #9
0
 def __init__(self, db, **kwargs):
     self.db = db
     TileStore.__init__(self, **kwargs)
Example #10
0
 def __init__(self, db, **kwargs):
     self.db = db
     TileStore.__init__(self, **kwargs)
Example #11
0
 def __init__(self, tilelayouts, headers=None, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.tilelayouts = tuple(tilelayouts)
     self.headers = headers or {}
Example #12
0
 def __init__(self, tile_stores, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.tile_stores = tile_stores
Example #13
0
 def __init__(self, tilestores, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.tilestores = tilestores
 def __init__(self, tilelayout, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.tilelayout = tilelayout
Example #15
0
 def __init__(self, tiles=None, **kwargs):
     self.tiles = tiles or {}
     TileStore.__init__(self, **kwargs)
Example #16
0
 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))
Example #17
0
 def test_load_https(self):
     from tilecloud.store.url import URLTileStore
     self.assertTrue(isinstance(TileStore.load('https://'), URLTileStore))
Example #18
0
 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)
Example #19
0
 def __init__(self, bounding_pyramid=None, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.bounding_pyramid = bounding_pyramid or BoundingPyramid()
Example #20
0
 def __init__(self, tilelayout, file=None, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.tilelayout = tilelayout
     self.file = file
Example #21
0
 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
Example #22
0
 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)
Example #24
0
 def __init__(self, tile_layout, lines=None, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.tile_layout = tile_layout
     self.lines = lines
Example #25
0
 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)
Example #26
0
 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, stores, default_layer_name=None, **kwargs):
     TileStore.__init__(self, **kwargs)
     self._stores = stores
     self._default_store = self._stores.get(default_layer_name)
Example #28
0
 def __init__(self, queue, on_empty=maybe_stop, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.queue = queue
     self.on_empty = maybe_stop
Example #29
0
 def __init__(self, tilestore, filters, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.tilestore = tilestore
     self.filters = filters
Example #30
0
 def __init__(self, tilelayout, **kwargs):
     TileStore.__init__(self, **kwargs)
     assert tilelayout is not None
     self.tilelayout = tilelayout
Example #31
0
 def test_load_null(self):
     self.assertTrue(isinstance(TileStore.load('null://'), NullTileStore))
Example #32
0
 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
Example #33
0
 def test_load_s3(self):
     from tilecloud.store.s3 import S3TileStore
     self.assertTrue(isinstance(TileStore.load('s3://bucket/template'), S3TileStore))
Example #34
0
 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)