(
        self,
        dsquery,
        dstile,
        tilefilename='',
        )
Scales down query dataset to the tile dataset
Scales down query dataset to the tile dataset
Scales down query dataset to the tile dataset
def scale_query_to_tile(
        self,
        dsquery,
        dstile,
        tilefilename='',
        ):
        """Scales down query dataset to the tile dataset"""

        querysize = dsquery.RasterXSize
        tilesize = dstile.RasterXSize
        tilebands = dstile.RasterCount

        if self.options.resampling == 'average':

            # Function: gdal.RegenerateOverview()

            for i in range(1, tilebands + 1):

                # Black border around NODATA
                # if i != 4:
                #   dsquery.GetRasterBand(i).SetNoDataValue(0)

                res = gdal.RegenerateOverview(dsquery.GetRasterBand(i),
                        dstile.GetRasterBand(i), 'average')
                if res != 0:
                    self.error('RegenerateOverview() failed on %s, error %d'
                                % (tilefilename, res))
        elif self.options.resampling == 'antialias':

            # Scaling by PIL (Python Imaging Library) - improved Lanczos

            array = numpy.zeros((querysize, querysize, tilebands),
                                numpy.uint8)
            for i in range(tilebands):
                array[:, :, i] = \
                    gdalarray.BandReadAsArray(dsquery.GetRasterBand(i
                        + 1), 0, 0, querysize, querysize)
            im = Image.fromarray(array, 'RGBA')  # Always four bands
            im1 = im.resize((tilesize, tilesize), Image.ANTIALIAS)
            if os.path.exists(tilefilename):
                im0 = Image.open(tilefilename)
                im1 = Image.composite(im1, im0, im1)
            im1.save(tilefilename, self.tiledriver)
        else:

            # Other algorithms are implemented by gdal.ReprojectImage().

            dsquery.SetGeoTransform((
                0.0,
                tilesize / float(querysize),
                0.0,
                0.0,
                0.0,
                tilesize / float(querysize),
                ))
            dstile.SetGeoTransform((
                0.0,
                1.0,
                0.0,
                0.0,
                0.0,
                1.0,
                ))

            res = gdal.ReprojectImage(dsquery, dstile, None, None,
                    self.resampling)
            if res != 0:
                self.error('ReprojectImage() failed on %s, error %d'
                           % (tilefilename, res))
def scale_query_to_tile ( self , dsquery , dstile , tilefilename = '' , ) : querysize = dsquery . RasterXSize tilesize = dstile . RasterXSize tilebands = dstile . RasterCount if self . options . resampling == 'average' : # Function: gdal.RegenerateOverview() for i in range ( 1 , tilebands + 1 ) : # Black border around NODATA # if i != 4: #   dsquery.GetRasterBand(i).SetNoDataValue(0) res = gdal . RegenerateOverview ( dsquery . GetRasterBand ( i ) , dstile . GetRasterBand ( i ) , 'average' ) if res != 0 : self . error ( 'RegenerateOverview() failed on %s, error %d' % ( tilefilename , res ) ) elif self . options . resampling == 'antialias' : # Scaling by PIL (Python Imaging Library) - improved Lanczos array = numpy . zeros ( ( querysize , querysize , tilebands ) , numpy . uint8 ) for i in range ( tilebands ) : array [ : , : , i ] = gdalarray . BandReadAsArray ( dsquery . GetRasterBand ( i + 1 ) , 0 , 0 , querysize , querysize ) im = Image . fromarray ( array , 'RGBA' ) # Always four bands im1 = im . resize ( ( tilesize , tilesize ) , Image . ANTIALIAS ) if os . path . exists ( tilefilename ) : im0 = Image . open ( tilefilename ) im1 = Image . composite ( im1 , im0 , im1 ) im1 . save ( tilefilename , self . tiledriver ) else : # Other algorithms are implemented by gdal.ReprojectImage(). dsquery . SetGeoTransform ( ( 0.0 , tilesize / float ( querysize ) , 0.0 , 0.0 , 0.0 , tilesize / float ( querysize ) , ) ) dstile . SetGeoTransform ( ( 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 1.0 , ) ) res = gdal . ReprojectImage ( dsquery , dstile , None , None , self . resampling ) if res != 0 : self . error ( 'ReprojectImage() failed on %s, error %d' % ( tilefilename , res ) )