(self, arguments)
Constructor function - initialization
Constructor function - initialization
Constructor function - initialization
def __init__(self, arguments):
        """Constructor function - initialization"""

        self.stopped = False
        self.input = None
        self.output = None

        # Tile format

        self.tilesize = 256
        self.tiledriver = 'PNG'
        self.tileext = 'png'

        # Should we read bigger window of the input raster and scale it down?
        # Note: Modified leter by open_input()
        # Not for 'near' resampling
        # Not for Wavelet based drivers (JPEG2000, ECW, MrSID)
        # Not for 'raster' profile

        self.scaledquery = True

        # How big should be query window be for scaling down
        # Later on reset according the chosen resampling algorightm

        self.querysize = 4 * self.tilesize

        # Should we use Read on the input file for generating overview tiles?
        # Note: Modified later by open_input()
        # Otherwise the overview tiles are generated from existing underlying tiles

        self.overviewquery = False

        # RUN THE ARGUMENT PARSER:

        self.optparse_init()
        (self.options, self.args) = \
            self.parser.parse_args(args=arguments)
        if not self.args:
            self.error('No input file specified')

        # POSTPROCESSING OF PARSED ARGUMENTS:

        # Workaround for old versions of GDAL

        try:
            if self.options.verbose and self.options.resampling \
                == 'near' or gdal.TermProgress_nocb:
                pass
        except:
            self.error('This version of GDAL is not supported. Please upgrade to 1.6+.'
                       )

            # ,"You can try run crippled version of gdal2tiles with parameters: -v -r 'near'")

        # Is output directory the last argument?

        # Test output directory, if it doesn't exist

        if os.path.isdir(self.args[-1]) or len(self.args) > 1 \
            and not os.path.exists(self.args[-1]):
            self.output = self.args[-1]
            self.args = self.args[:-1]

        # More files on the input not directly supported yet

        if len(self.args) > 1:
            self.error('Processing of several input files is not supported.'
                       ,
                       """Please first use a tool like gdal_vrtmerge.py or gdal_merge.py on the files:
gdal_vrtmerge.py -o merged.vrt %s"""
                        % ' '.join(self.args))

            # TODO: Call functions from gdal_vrtmerge.py directly

        self.input = self.args[0]

        # Default values for not given options

        if not self.output:

            # Directory with input filename without extension in actual directory

            self.output = \
                os.path.splitext(os.path.basename(self.input))[0]

        if not self.options.title:
            self.options.title = os.path.basename(self.input)

        if self.options.url and not self.options.url.endswith('/'):
            self.options.url += '/'
        if self.options.url:
            self.options.url += os.path.basename(self.output) + '/'

        # Supported options

        self.resampling = None

        if self.options.resampling == 'average':
            try:
                if gdal.RegenerateOverview:
                    pass
            except:
                self.error("'average' resampling algorithm is not available."
                           ,
                           "Please use -r 'near' argument or upgrade to newer version of GDAL."
                           )
        elif self.options.resampling == 'antialias':

            try:
                if numpy:
                    pass
            except:
                self.error("'antialias' resampling algorithm is not available."
                           ,
                           'Install PIL (Python Imaging Library) and numpy.'
                           )
        elif self.options.resampling == 'near':

            self.resampling = gdal.GRA_NearestNeighbour
            self.querysize = self.tilesize
        elif self.options.resampling == 'bilinear':

            self.resampling = gdal.GRA_Bilinear
            self.querysize = self.tilesize * 2
        elif self.options.resampling == 'cubic':

            self.resampling = gdal.GRA_Cubic
        elif self.options.resampling == 'cubicspline':

            self.resampling = gdal.GRA_CubicSpline
        elif self.options.resampling == 'lanczos':

            self.resampling = gdal.GRA_Lanczos

        # User specified zoom levels

        self.tminz = None
        self.tmaxz = None
        if self.options.zoom:
            minmax = self.options.zoom.split('-', 1)
            minmax.extend([''])
            (min, max) = minmax[:2]
            self.tminz = int(min)
            if max:
                self.tmaxz = int(max)
            else:
                self.tmaxz = int(min)

        # KML generation

        self.kml = self.options.kml

        # Output the results

        if self.options.verbose:
            print('Options:', self.options)
            print('Input:', self.input)
            print('Output:', self.output)
            print('Cache: %s MB' % (gdal.GetCacheMax() / 1024 / 1024))
            print('')
def __init__ ( self , arguments ) : self . stopped = False self . input = None self . output = None # Tile format self . tilesize = 256 self . tiledriver = 'PNG' self . tileext = 'png' # Should we read bigger window of the input raster and scale it down? # Note: Modified leter by open_input() # Not for 'near' resampling # Not for Wavelet based drivers (JPEG2000, ECW, MrSID) # Not for 'raster' profile self . scaledquery = True # How big should be query window be for scaling down # Later on reset according the chosen resampling algorightm self . querysize = 4 * self . tilesize # Should we use Read on the input file for generating overview tiles? # Note: Modified later by open_input() # Otherwise the overview tiles are generated from existing underlying tiles self . overviewquery = False # RUN THE ARGUMENT PARSER: self . optparse_init ( ) ( self . options , self . args ) = self . parser . parse_args ( args = arguments ) if not self . args : self . error ( 'No input file specified' ) # POSTPROCESSING OF PARSED ARGUMENTS: # Workaround for old versions of GDAL try : if self . options . verbose and self . options . resampling == 'near' or gdal . TermProgress_nocb : pass except : self . error ( 'This version of GDAL is not supported. Please upgrade to 1.6+.' ) # ,"You can try run crippled version of gdal2tiles with parameters: -v -r 'near'") # Is output directory the last argument? # Test output directory, if it doesn't exist if os . path . isdir ( self . args [ - 1 ] ) or len ( self . args ) > 1 and not os . path . exists ( self . args [ - 1 ] ) : self . output = self . args [ - 1 ] self . args = self . args [ : - 1 ] # More files on the input not directly supported yet if len ( self . args ) > 1 : self . error ( 'Processing of several input files is not supported.' , """Please first use a tool like gdal_vrtmerge.py or gdal_merge.py on the files:
gdal_vrtmerge.py -o merged.vrt %s""" % ' ' . join ( self . args ) ) # TODO: Call functions from gdal_vrtmerge.py directly self . input = self . args [ 0 ] # Default values for not given options if not self . output : # Directory with input filename without extension in actual directory self . output = os . path . splitext ( os . path . basename ( self . input ) ) [ 0 ] if not self . options . title : self . options . title = os . path . basename ( self . input ) if self . options . url and not self . options . url . endswith ( '/' ) : self . options . url += '/' if self . options . url : self . options . url += os . path . basename ( self . output ) + '/' # Supported options self . resampling = None if self . options . resampling == 'average' : try : if gdal . RegenerateOverview : pass except : self . error ( "'average' resampling algorithm is not available." , "Please use -r 'near' argument or upgrade to newer version of GDAL." ) elif self . options . resampling == 'antialias' : try : if numpy : pass except : self . error ( "'antialias' resampling algorithm is not available." , 'Install PIL (Python Imaging Library) and numpy.' ) elif self . options . resampling == 'near' : self . resampling = gdal . GRA_NearestNeighbour self . querysize = self . tilesize elif self . options . resampling == 'bilinear' : self . resampling = gdal . GRA_Bilinear self . querysize = self . tilesize * 2 elif self . options . resampling == 'cubic' : self . resampling = gdal . GRA_Cubic elif self . options . resampling == 'cubicspline' : self . resampling = gdal . GRA_CubicSpline elif self . options . resampling == 'lanczos' : self . resampling = gdal . GRA_Lanczos # User specified zoom levels self . tminz = None self . tmaxz = None if self . options . zoom : minmax = self . options . zoom . split ( '-' , 1 ) minmax . extend ( [ '' ] ) ( min , max ) = minmax [ : 2 ] self . tminz = int ( min ) if max : self . tmaxz = int ( max ) else : self . tmaxz = int ( min ) # KML generation self . kml = self . options . kml # Output the results if self . options . verbose : print ( 'Options:' , self . options ) print ( 'Input:' , self . input ) print ( 'Output:' , self . output ) print ( 'Cache: %s MB' % ( gdal . GetCacheMax ( ) / 1024 / 1024 ) ) print ( '' )