How to use the gdal.AllRegister function in GDAL

To help you get started, we’ve selected a few GDAL examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github npolar / RemoteSensing / MetIceCharts / IceChartStatistics.py View on Github external
def CountIcetype(infile, outfilepath):
    '''
    Count pixels of a given number=days of fast ice
    '''
    
    #Define filenames
    (infilepath, infilename) =  os.path.split(infile)       #get path and filename seperately
    (infileshortname, extension) = os.path.splitext(infilename)
    
    outputtextfile = outfilepath + '\\' + infileshortname + '_PixelCount.txt'
    
    # register all of the GDAL drivers
    gdal.AllRegister()
    
    # open the image
    ds = gdal.Open(infile, gdalconst.GA_ReadOnly)
    if ds is None:
        print 'Could not open ', infileshortname
        sys.exit(1)

    # get image size
    rows = ds.RasterYSize
    cols = ds.RasterXSize
    totalpixels = rows * cols

    #Read input raster into array
    iceraster = ds.ReadAsArray()
    
    # initialize variable
github OSGeo / gdal / pymod / gdalchksum.py View on Github external
import sys

def Usage():
    print 'Usage: gdalchksum.py [-b band] [-srcwin xoff yoff xsize ysize] file'
    sys.exit(1)

# =============================================================================
# 	Mainline
# =============================================================================

srcwin = None
bands = []

filename = None

gdal.AllRegister()
argv = gdal.GeneralCmdLineProcessor( sys.argv )
if argv is None:
    sys.exit( 0 )

# Parse command line arguments.
i = 1
while i < len(argv):
    arg = argv[i]

    if arg == '-b':
        i = i + 1
        bands.append( int(argv[i]) )

    elif arg == '-srcwin':
        srcwin = [int(argv[i+1]),int(argv[i+2]),
                  int(argv[i+3]),int(argv[i+3]) ]
github npolar / RemoteSensing / SeaIceFrequency / SeaIceFrequency.py View on Github external
def CreateMaxMinIce(inpath, outfilepath, landmask_raster, coastalerrormask_raster, oceanmask_buffer5, NSIDC_balticmask ):   
    ''' 
         Creates maximum and minimum ice map, GeoTIFF and shapefile
         maximum = at least one day ice at this pixel
         minimum = every day ice at this pixel
         In addition a file simply giving the number of days with ice
         
         The poly shapefile has all features as polygon, the line shapefile
         only the max or min ice edge
    
    '''
    
    #register all gdal drivers
    gdal.AllRegister()
    
    # Iterate through all rasterfiles
    # filelist is all GeoTIFF files created in outfilepath
    filelist = glob.glob(outfilepath + 'nt*.tif')
    
    #Determine Number of Days from available ice chart files
    NumberOfDays = len(filelist)
    
    #Files are all the same properties, so take first one to get info
    firstfilename = filelist[0]
    
    #Define file names 
    (infilepath, infilename) = os.path.split(firstfilename)             #get path and filename seperately
    (infileshortname, extension) = os.path.splitext(infilename)
    
    outfile =  inpath + 'icechart_NumberOfDays' + os.path.split(filelist[0])[1][3:9] + '_' + os.path.split(filelist[-1])[1][3:9] + '.tif'
github ofringer / suntanspy / GIS / maptools.py View on Github external
def readraster(infile):
    """ Loads the data from any raster-type file
        eg. *.dem, *.grd,...    
    """
    # register all of the drivers
    gdal.AllRegister()
    # open the image
    ds = gdal.Open(infile, GA_ReadOnly)
    
    # Read the x and y coordinates
    cols = ds.RasterXSize
    rows = ds.RasterYSize
    bands = ds.RasterCount
    
    geotransform = ds.GetGeoTransform()
    originX = geotransform[0]
    originY = geotransform[3]
    pixelWidth = geotransform[1]
    pixelHeight = geotransform[5]
    
    x = originX + np.linspace(0,cols-1,cols)*pixelWidth
    y = originY + np.linspace(0,rows-1,rows)*pixelHeight
github GitHubRGI / geopackage-python / Tiling / gdal2tiles_parallel.py View on Github external
def open_input(self):
        """Initialization of the input raster, reprojection if necessary"""

        gdal.UseExceptions()
        gdal.AllRegister()
        if not self.options.verbose:
            gdal.PushErrorHandler('CPLQuietErrorHandler')

        # Initialize necessary GDAL drivers

        self.out_drv = gdal.GetDriverByName(self.tiledriver)
        self.mem_drv = gdal.GetDriverByName('MEM')

        if not self.out_drv:
            raise Exception(
                "The '%s' driver was not found, is it available in this GDAL build?",
                self.tiledriver)
        if not self.mem_drv:
            raise Exception(
                "The 'MEM' driver was not found, is it available in this GDAL build?")
github ofringer / suntanspy / GIS / maptools.py View on Github external
def readDEM(bathyfile,returnvec=False):
    """ Loads the data from a DEM file"""
    # register all of the drivers
    gdal.AllRegister()
    # open the image
    ds = gdal.Open(bathyfile, GA_ReadOnly)
    
    # Read the x and y coordinates
    cols = ds.RasterXSize
    rows = ds.RasterYSize
    bands = ds.RasterCount
    
    geotransform = ds.GetGeoTransform()
    originX = geotransform[0]
    originY = geotransform[3]
    pixelWidth = geotransform[1]
    pixelHeight = geotransform[5]
    
    x = originX + np.linspace(0,cols-1,cols)*pixelWidth
    y = originY + np.linspace(0,rows-1,rows)*pixelHeight
github mortcanty / CRCPython / src / CHAPTER1 / dispms.py View on Github external
def dispms(filename=None,dims=None,rgb=None,enhance=None):
    gdal.AllRegister()
    if filename == None:        
        filename = auxil.select_infile(title='Choose an image to display') 
    if filename:                   
        inDataset = gdal.Open(filename,GA_ReadOnly)     
        cols =  inDataset.RasterXSize
        rows =  inDataset.RasterYSize    
        bands = inDataset.RasterCount
    else:
        return 
    if dims == None:
        dims = auxil.select_dims([0,0,cols,rows])
    if dims:
        x0,y0,cols,rows = dims
    else:
        return
    if rgb == None:
github ocapmod / OCAP / tiles_tut / gdal2tiles_legacy_no-tms.py View on Github external
def open_input(self):
		"""Initialization of the input raster, reprojection if necessary"""
		
		gdal.AllRegister()

		# Initialize necessary GDAL drivers
		
		self.out_drv = gdal.GetDriverByName( self.tiledriver )
		self.mem_drv = gdal.GetDriverByName( 'MEM' )
		
		if not self.out_drv:
			raise Exception("The '%s' driver was not found, is it available in this GDAL build?", self.tiledriver)
		if not self.mem_drv:
			raise Exception("The 'MEM' driver was not found, is it available in this GDAL build?")
		
		# Open the input file
		
		if self.input:
			self.in_ds = gdal.Open(self.input, gdal.GA_ReadOnly)
		else:
github commenthol / gdal2tiles-leaflet / gdal2tiles-multiprocess.py View on Github external
def open_input(self):
        """Initialization of the input raster, reprojection if necessary"""

        gdal.UseExceptions()
        gdal.AllRegister()
        if not self.options.verbose:
            gdal.PushErrorHandler('CPLQuietErrorHandler')

        # Initialize necessary GDAL drivers

        self.out_drv = gdal.GetDriverByName(self.tiledriver)
        self.mem_drv = gdal.GetDriverByName('MEM')

        if not self.out_drv:
            raise Exception("The '%s' driver was not found, is it available in this GDAL build?"
                            , self.tiledriver)
        if not self.mem_drv:
            raise Exception("The 'MEM' driver was not found, is it available in this GDAL build?"
                            )

        # Open the input file
github npolar / RemoteSensing / MetIceCharts / IceChart2.py View on Github external
MUCH TOO COMPLICATED ___ LOOK AT IceChartProcessing.py SCRIPT
    '''
    # Create a list of all available raster icechart files
    filelist = sorted(glob.glob('C:\Users\max\Documents\Icecharts\Data\Kit\EPSG3575\*EPSG3575.tif'))
    
    #Settings
    #Year to be analyzed but then from 15 March til 30 April -- read from first file
    year = int(filelist[0][54:58])
        
    
    outfilepath = 'C:\\Users\\max\\Documents\\Icecharts\Data\\Kit\\EPSG3575'
    
    print 'Search for missing files and replace with precious ones'
    #register all gdal drivers
    gdal.AllRegister()
    

    
    #Check all dates in march
    #Read first filename and determine first available date, format mmdd
    date = int(filelist[0][58:62])
    
    #loop through files from first file to end of month
    for i in range(date, 332):
        
        #compile file name to be searched for
        filename = outfilepath + '\\ice' + str(year) + '0' + str(i) + '_EPSG3575.tif'
        
        
        if (filename in filelist) == False: