(self)
Generation of the overview tiles (higher in the pyramid) based on existing tiles
Generation of the overview tiles (higher in the pyramid) based on existing tiles
Generation of the overview tiles ( higher in the pyramid ) based on existing tiles
def generate_overview_tiles(self):
        """Generation of the overview tiles (higher in the pyramid) based on existing tiles"""

        print('Generating Overview Tiles:')

        tilebands = self.dataBandsCount + 1

        # Usage of existing tiles: from 4 underlying tiles generate one as overview.

        tcount = 0
        for tz in range(self.tmaxz - 1, self.tminz - 1, -1):
            (tminx, tminy, tmaxx, tmaxy) = self.tminmax[tz]
            tcount += (1 + abs(tmaxx - tminx)) * (1 + abs(tmaxy
                    - tminy))

        ti = 0

        # querysize = tilesize * 2

        for tz in range(self.tmaxz - 1, self.tminz - 1, -1):
            (tminx, tminy, tmaxx, tmaxy) = self.tminmax[tz]
            yrange = range(tmaxy, tminy - 1, -1)
            if self.options.leaflet:
                yrange = range(tminy, tmaxy + 1)
            for ty in yrange:
                for tx in range(tminx, tmaxx + 1):

                    if self.stopped:
                        break

                    ti += 1
                    tilefilename = os.path.join(self.output, str(tz),
                            str(tx), '%s.%s' % (ty, self.tileext))

                    if self.options.verbose:
                        print (ti, '/', tcount, tilefilename)  # , "( TileMapService: z / x / y )"

                    if self.options.resume \
                        and os.path.exists(tilefilename):
                        if self.options.verbose:
                            print('Tile generation skiped because of --resume')
                        else:
                            self.progressbar(ti / float(tcount))
                        continue

                    # Create directories for the tile

                    if not os.path.exists(os.path.dirname(tilefilename)):
                        os.makedirs(os.path.dirname(tilefilename))

                    dsquery = self.mem_drv.Create('', 2
                            * self.tilesize, 2 * self.tilesize,
                            tilebands)

                    # TODO: fill the null value
                    # for i in range(1, tilebands+1):
                    #   dsquery.GetRasterBand(1).Fill(tilenodata)

                    dstile = self.mem_drv.Create('', self.tilesize,
                            self.tilesize, tilebands)

                    # TODO: Implement more clever walking on the tiles with cache functionality
                    # probably walk should start with reading of four tiles from top left corner
                    # Hilbert curve

                    children = []

                    # Read the tiles and write them to query window

                    for y in range(2 * ty, 2 * ty + 2):
                        for x in range(2 * tx, 2 * tx + 2):
                            (minx, miny, maxx, maxy) = self.tminmax[tz
                                    + 1]
                            if x >= minx and x <= maxx and y >= miny \
                                and y <= maxy:
                                dsquerytile = \
                                    gdal.Open(os.path.join(self.output,
                                        str(tz + 1), str(x), '%s.%s'
                                        % (y, self.tileext)),
                                        gdal.GA_ReadOnly)

                                if self.options.leaflet:
                                    if ty:
                                        tileposy = y % (2 * ty) \
    * self.tilesize
                                    elif ty == 0 and y == 1:
                                        tileposy = self.tilesize
                                    else:
                                        tileposy = 0
                                else:
                                    if ty == 0 and y == 1 or ty != 0 \
    and y % (2 * ty) != 0:
                                        tileposy = 0
                                    else:
                                        tileposy = self.tilesize

                                if tx:
                                    tileposx = x % (2 * tx) \
    * self.tilesize
                                elif tx == 0 and x == 1:
                                    tileposx = self.tilesize
                                else:
                                    tileposx = 0
                                dsquery.WriteRaster(
                                    tileposx,
                                    tileposy,
                                    self.tilesize,
                                    self.tilesize,
                                    dsquerytile.ReadRaster(0, 0,
        self.tilesize, self.tilesize),
                                    band_list=list(range(1, tilebands
        + 1)),
                                    )
                                children.append([x, y, tz + 1])

                    self.scale_query_to_tile(dsquery, dstile,
                            tilefilename)

                    # Write a copy of tile to png/jpg

                    if self.options.resampling != 'antialias':

                        # Write a copy of tile to png/jpg

                        self.out_drv.CreateCopy(tilefilename, dstile,
                                strict=0)

                    if self.options.verbose:
                        print (
                            '\tbuild from zoom',
                            tz + 1,
                            ' tiles:',
                            (2 * tx, 2 * ty),
                            (2 * tx + 1, 2 * ty),
                            (2 * tx, 2 * ty + 1),
                            (2 * tx + 1, 2 * ty + 1),
                            )

                    # Create a KML file for this tile.

                    if self.kml:
                        f = open(os.path.join(self.output,
                                 '%d/%d/%d.kml' % (tz, tx, ty)), 'w')
                        f.write(self.generate_kml(tx, ty, tz, children))
                        f.close()

                    if not self.options.verbose:
                        self.progressbar(ti / float(tcount))
def generate_overview_tiles ( self ) : print ( 'Generating Overview Tiles:' ) tilebands = self . dataBandsCount + 1 # Usage of existing tiles: from 4 underlying tiles generate one as overview. tcount = 0 for tz in range ( self . tmaxz - 1 , self . tminz - 1 , - 1 ) : ( tminx , tminy , tmaxx , tmaxy ) = self . tminmax [ tz ] tcount += ( 1 + abs ( tmaxx - tminx ) ) * ( 1 + abs ( tmaxy - tminy ) ) ti = 0 # querysize = tilesize * 2 for tz in range ( self . tmaxz - 1 , self . tminz - 1 , - 1 ) : ( tminx , tminy , tmaxx , tmaxy ) = self . tminmax [ tz ] yrange = range ( tmaxy , tminy - 1 , - 1 ) if self . options . leaflet : yrange = range ( tminy , tmaxy + 1 ) for ty in yrange : for tx in range ( tminx , tmaxx + 1 ) : if self . stopped : break ti += 1 tilefilename = os . path . join ( self . output , str ( tz ) , str ( tx ) , '%s.%s' % ( ty , self . tileext ) ) if self . options . verbose : print ( ti , '/' , tcount , tilefilename ) # , "( TileMapService: z / x / y )" if self . options . resume and os . path . exists ( tilefilename ) : if self . options . verbose : print ( 'Tile generation skiped because of --resume' ) else : self . progressbar ( ti / float ( tcount ) ) continue # Create directories for the tile if not os . path . exists ( os . path . dirname ( tilefilename ) ) : os . makedirs ( os . path . dirname ( tilefilename ) ) dsquery = self . mem_drv . Create ( '' , 2 * self . tilesize , 2 * self . tilesize , tilebands ) # TODO: fill the null value # for i in range(1, tilebands+1): #   dsquery.GetRasterBand(1).Fill(tilenodata) dstile = self . mem_drv . Create ( '' , self . tilesize , self . tilesize , tilebands ) # TODO: Implement more clever walking on the tiles with cache functionality # probably walk should start with reading of four tiles from top left corner # Hilbert curve children = [ ] # Read the tiles and write them to query window for y in range ( 2 * ty , 2 * ty + 2 ) : for x in range ( 2 * tx , 2 * tx + 2 ) : ( minx , miny , maxx , maxy ) = self . tminmax [ tz + 1 ] if x >= minx and x <= maxx and y >= miny and y <= maxy : dsquerytile = gdal . Open ( os . path . join ( self . output , str ( tz + 1 ) , str ( x ) , '%s.%s' % ( y , self . tileext ) ) , gdal . GA_ReadOnly ) if self . options . leaflet : if ty : tileposy = y % ( 2 * ty ) * self . tilesize elif ty == 0 and y == 1 : tileposy = self . tilesize else : tileposy = 0 else : if ty == 0 and y == 1 or ty != 0 and y % ( 2 * ty ) != 0 : tileposy = 0 else : tileposy = self . tilesize if tx : tileposx = x % ( 2 * tx ) * self . tilesize elif tx == 0 and x == 1 : tileposx = self . tilesize else : tileposx = 0 dsquery . WriteRaster ( tileposx , tileposy , self . tilesize , self . tilesize , dsquerytile . ReadRaster ( 0 , 0 , self . tilesize , self . tilesize ) , band_list = list ( range ( 1 , tilebands + 1 ) ) , ) children . append ( [ x , y , tz + 1 ] ) self . scale_query_to_tile ( dsquery , dstile , tilefilename ) # Write a copy of tile to png/jpg if self . options . resampling != 'antialias' : # Write a copy of tile to png/jpg self . out_drv . CreateCopy ( tilefilename , dstile , strict = 0 ) if self . options . verbose : print ( '\tbuild from zoom' , tz + 1 , ' tiles:' , ( 2 * tx , 2 * ty ) , ( 2 * tx + 1 , 2 * ty ) , ( 2 * tx , 2 * ty + 1 ) , ( 2 * tx + 1 , 2 * ty + 1 ) , ) # Create a KML file for this tile. if self . kml : f = open ( os . path . join ( self . output , '%d/%d/%d.kml' % ( tz , tx , ty ) ) , 'w' ) f . write ( self . generate_kml ( tx , ty , tz , children ) ) f . close ( ) if not self . options . verbose : self . progressbar ( ti / float ( tcount ) )