Esempio n. 1
0
 def _tile_location_tc(self, tile, create_dir=False):
     """
     Return the location of the `tile`. Caches the result as ``location``
     property of the `tile`.
     
     :param tile: the tile object
     :param create_dir: if True, create all necessary directories
     :return: the full filename of the tile
     
     >>> from mapproxy.cache.tile import Tile
     >>> c = FileCache(cache_dir='/tmp/cache/', file_ext='png')
     >>> c.tile_location(Tile((3, 4, 2))).replace('\\\\', '/')
     '/tmp/cache/02/000/000/003/000/000/004.png'
     """
     if tile.location is None:
         x, y, z = tile.coord
         parts = (self.level_location(z),
                  "%03d" % int(x / 1000000),
                  "%03d" % (int(x / 1000) % 1000),
                  "%03d" % (int(x) % 1000),
                  "%03d" % int(y / 1000000),
                  "%03d" % (int(y / 1000) % 1000),
                  "%03d.%s" % (int(y) % 1000, self.file_ext))
         tile.location = os.path.join(*parts)
     if create_dir:
         ensure_directory(tile.location)
     return tile.location
Esempio n. 2
0
    def _tile_location_quadkey(self, tile, create_dir=False):
        """
        Return the location of the `tile`. Caches the result as ``location``
        property of the `tile`.

        :param tile: the tile object
        :param create_dir: if True, create all necessary directories
        :return: the full filename of the tile

        >>> from mapproxy.cache.tile import Tile
        >>> from mapproxy.cache.file import FileCache
        >>> c = FileCache(cache_dir='/tmp/cache/', file_ext='png', directory_layout='quadkey')
        >>> c.tile_location(Tile((3, 4, 2))).replace('\\\\', '/')
        '/tmp/cache/11.png'
        """
        if tile.location is None:
            x, y, z = tile.coord
            quadKey = ""
            for i in range(z,0,-1):
                digit = 0
                mask = 1 << (i-1)
                if (x & mask) != 0:
                    digit += 1
                if (y & mask) != 0:
                    digit += 2
                quadKey += str(digit)
            tile.location = os.path.join( 
                self.cache_dir, quadKey + '.' + self.file_ext
            )
        if create_dir:
            ensure_directory(tile.location)
        return tile.location
Esempio n. 3
0
 def _single_color_tile_location(self, color, create_dir=False):
     """
     >>> c = FileCache(cache_dir='/tmp/cache/', file_ext='png')
     >>> c._single_color_tile_location((254, 0, 4)).replace('\\\\', '/')
     '/tmp/cache/single_color_tiles/fe0004.png'
     """
     parts = (
         self.cache_dir,
         'single_color_tiles',
         ''.join('%02x' % v for v in color) + '.' + self.file_ext
     )
     location = os.path.join(*parts)
     if create_dir:
         ensure_directory(location)
     return location
Esempio n. 4
0
 def store(self, legend):
     if legend.stored:
         return
     
     if legend.location is None:
         hash = legend_hash(legend.id, legend.scale)
         legend.location = os.path.join(self.cache_dir, hash) + '.' + self.file_ext
         ensure_directory(legend.location)
     
     data = legend.source.as_buffer(ImageOptions(format='image/' + self.file_ext), seekable=True)
     data.seek(0)
     with open(legend.location, 'wb') as f:
         log.debug('writing to %s' % (legend.location))
         f.write(data.read())
     data.seek(0)
     legend.stored = True
Esempio n. 5
0
    def store(self, legend):
        if legend.stored:
            return

        if legend.location is None:
            hash = legend_hash(legend.id, legend.scale)
            legend.location = os.path.join(self.cache_dir,
                                           hash) + '.' + self.file_ext
            ensure_directory(legend.location)

        data = legend.source.as_buffer(ImageOptions(format='image/' +
                                                    self.file_ext),
                                       seekable=True)
        data.seek(0)
        with open(legend.location, 'wb') as f:
            log.debug('writing to %s' % (legend.location))
            f.write(data.read())
        data.seek(0)
        legend.stored = True
Esempio n. 6
0
 def _tile_location_tms(self, tile, create_dir=False):
     """
     Return the location of the `tile`. Caches the result as ``location``
     property of the `tile`.
     
     :param tile: the tile object
     :param create_dir: if True, create all necessary directories
     :return: the full filename of the tile
     
     >>> from mapproxy.cache.tile import Tile
     >>> c = FileCache(cache_dir='/tmp/cache/', file_ext='png', directory_layout='tms')
     >>> c.tile_location(Tile((3, 4, 2))).replace('\\\\', '/')
     '/tmp/cache/2/3/4.png'
     """
     if tile.location is None:
         x, y, z = tile.coord
         tile.location = os.path.join(
             self.level_location(str(z)),
             str(x), str(y) + '.' + self.file_ext
         )
     if create_dir:
         ensure_directory(tile.location)
     return tile.location