Python osgeo.gdal.GetDataTypeName() Examples

The following are 9 code examples of osgeo.gdal.GetDataTypeName(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module osgeo.gdal , or try the search function .
Example #1
Source File: LSDMappingTools.py    From LSDMappingTools with MIT License 7 votes vote down vote up
def GetGeoInfo(FileName):

    if exists(FileName) is False:
            raise Exception('[Errno 2] No such file or directory: \'' + FileName + '\'')    
    
    
    SourceDS = gdal.Open(FileName, gdal.GA_ReadOnly)
    if SourceDS == None:
        raise Exception("Unable to read the data file")
    
    NDV = SourceDS.GetRasterBand(1).GetNoDataValue()
    xsize = SourceDS.RasterXSize
    ysize = SourceDS.RasterYSize
    GeoT = SourceDS.GetGeoTransform()
    Projection = osr.SpatialReference()
    Projection.ImportFromWkt(SourceDS.GetProjectionRef())
    DataType = SourceDS.GetRasterBand(1).DataType
    DataType = gdal.GetDataTypeName(DataType)
    
    return NDV, xsize, ysize, GeoT, Projection, DataType
#==============================================================================

#==============================================================================
# Function to read the original file's projection: 
Example #2
Source File: hand_floodfill.py    From FloodMapsWorkshop with Apache License 2.0 6 votes vote down vote up
def get_reference_water_data(self):
		ds = self.get_reference_water_dataset()
		
		band = ds.GetRasterBand(1)
		#print 'Band Type=',gdal.GetDataTypeName(band.DataType)

		#min = band.GetMinimum()
		#max = band.GetMaximum()
		#if min is None or max is None:
		#	(min,max) = band.ComputeRasterMinMax(1)
		#	print 'Min=%.3f, Max=%.3f' % (min,max)

		data = band.ReadAsArray(0, 0, ds.RasterXSize, ds.RasterYSize )
		# Read individual pixels using [yoff, xoff]
		# (math matrix notation is [row,col], not [x,y])
		
		return data 
Example #3
Source File: hand.py    From FloodMapsWorkshop with Apache License 2.0 6 votes vote down vote up
def get_reference_water_data(self):
		ds = self.get_reference_water_dataset()
		
		band = ds.GetRasterBand(1)
		#print 'Band Type=',gdal.GetDataTypeName(band.DataType)

		#min = band.GetMinimum()
		#max = band.GetMaximum()
		#if min is None or max is None:
		#	(min,max) = band.ComputeRasterMinMax(1)
		#	print 'Min=%.3f, Max=%.3f' % (min,max)

		data = band.ReadAsArray(0, 0, ds.RasterXSize, ds.RasterYSize )
		# Read individual pixels using [yoff, xoff]
		# (math matrix notation is [row,col], not [x,y])
		
		return data 
Example #4
Source File: LSDMap_GDALIO.py    From LSDMappingTools with MIT License 5 votes vote down vote up
def GetGeoInfo(FileName):
    """This gets information from the raster file using gdal

    Args:
        FileName (str): The filename (with path and extension) of the raster.

    Return:
        float: A vector that contains:
            * NDV: the nodata values
            * xsize: cellsize in x direction
            * ysize: cellsize in y direction
            * GeoT: the tranform (a string)
            * Projection: the Projection (a string)
            * DataType: The type of data (an int explaing the bits of each data element)

    Author: SMM
    """


    if exists(FileName) is False:
            raise Exception('[Errno 2] No such file or directory: \'' + FileName + '\'')


    SourceDS = gdal.Open(FileName, gdal.GA_ReadOnly)
    if SourceDS == None:
        raise Exception("Unable to read the data file")

    NDV = SourceDS.GetRasterBand(1).GetNoDataValue()
    xsize = SourceDS.RasterXSize
    ysize = SourceDS.RasterYSize
    GeoT = SourceDS.GetGeoTransform()
    Projection = osr.SpatialReference()
    Projection.ImportFromWkt(SourceDS.GetProjectionRef())
    DataType = SourceDS.GetRasterBand(1).DataType
    DataType = gdal.GetDataTypeName(DataType)

    return NDV, xsize, ysize, GeoT, Projection, DataType
#==============================================================================

#==============================================================================
# This gets the UTM zone, if it exists 
Example #5
Source File: georasters.py    From georasters with GNU General Public License v3.0 5 votes vote down vote up
def get_geo_info(filename, band=1):
    ''' Gets information from a Raster data set
    '''
    sourceds = gdal.Open(filename, GA_ReadOnly)
    ndv = sourceds.GetRasterBand(band).GetNoDataValue()
    xsize = sourceds.RasterXSize
    ysize = sourceds.RasterYSize
    geot = sourceds.GetGeoTransform()
    projection = osr.SpatialReference()
    projection.ImportFromWkt(sourceds.GetProjectionRef())
    datatype = sourceds.GetRasterBand(band).DataType
    datatype = gdal.GetDataTypeName(datatype)
    return ndv, xsize, ysize, geot, projection, datatype

# Function to map location in pixel of raster array 
Example #6
Source File: hand_floodfill.py    From FloodMapsWorkshop with Apache License 2.0 5 votes vote down vote up
def get_bil_data(self, dataset):
		band = dataset.GetRasterBand(1)
		#print 'Band Type=',gdal.GetDataTypeName(band.DataType)
		data = band.ReadAsArray(0, 0, dataset.RasterXSize, dataset.RasterYSize )

		return data

	#	
	# Convert from EPSG:3857 meters to EPSG:4326 latlng
	# 
Example #7
Source File: hand.py    From FloodMapsWorkshop with Apache License 2.0 5 votes vote down vote up
def get_bil_data(self, dataset):
		band = dataset.GetRasterBand(1)
		#print 'Band Type=',gdal.GetDataTypeName(band.DataType)
		data = band.ReadAsArray(0, 0, dataset.RasterXSize, dataset.RasterYSize )

		return data

	#	
	# Convert from EPSG:3857 meters to EPSG:4326 latlng
	# 
Example #8
Source File: georaster.py    From BlenderGIS with GNU General Public License v3.0 5 votes vote down vote up
def _fromGDAL(self):
		'''Use GDAL to extract raster infos and init'''
		if self.path is None or not self.fileExists:
			raise IOError("Cannot find file on disk")
		ds = gdal.Open(self.path, gdal.GA_ReadOnly)
		self.size = xy(ds.RasterXSize, ds.RasterYSize)
		self.format = ds.GetDriver().ShortName
		if self.format in ['JP2OpenJPEG', 'JP2ECW', 'JP2KAK', 'JP2MrSID'] :
			self.format = 'JPEG2000'
		self.nbBands = ds.RasterCount
		b1 = ds.GetRasterBand(1) #first band (band index does not count from 0)
		self.noData = b1.GetNoDataValue()
		ddtype = gdal.GetDataTypeName(b1.DataType)#Byte, UInt16, Int16, UInt32, Int32, Float32, Float64
		if ddtype == "Byte":
			self.dtype = 'uint'
			self.depth = 8
		else:
			self.dtype = ddtype[0:len(ddtype)-2].lower()
			self.depth = int(ddtype[-2:])
		#Get Georef
		self.georef = GeoRef.fromGDAL(ds)
		#Close (gdal has no garbage collector)
		ds, b1 = None, None

	#######################################
	# Dynamic properties
	####################################### 
Example #9
Source File: georaster.py    From georaster with MIT License 4 votes vote down vote up
def __init__(self,ds_filename,load_data=True,latlon=True,band=1,
        spatial_ref=None,geo_transform=None,downsampl=1):
        """ Open a single band raster.
        
        :param ds_filename: filename of the dataset to import
        :type ds_filename: str
        
        :param load_data: If True, to import the data into obj.r.  If False, 
        do not load any data. Provide tuple (left, right, bottom, top) to load 
        subset, in which case extent will be set to reflect subset area.
        :type load_data: 


            latlon : default True. Only used if load_data=tuple. Set as False
                     if tuple is projected coordinates, True if WGS84.
            band : default 1. Specify GDAL band number to load. If you want to
                   load multiple bands at once use MultiBandRaster instead.
            downsampl : default 1. Used to down-sample the image when loading it. 
                A value of 2 for example will multiply the resolution by 2. 

            Optionally, you can manually specify/override the georeferencing. 
            To do this you must set both of the following parameters:

            spatial_ref : a OSR SpatialReference instance
            geo_transform : a Geographic Transform tuple of the form 
                            (top left x, w-e cell size, 0, top left y, 0, 
                             n-s cell size (-ve))
            
        """

        # Do basic dataset loading - set up georeferencing
        self._load_ds(ds_filename,spatial_ref=spatial_ref,
                      geo_transform=geo_transform)

        # Import band datatype
        band_tmp = self.ds.GetRasterBand(band)
        self.dtype = gdal.GetDataTypeName(band_tmp.DataType)
        
        # Load entire image
        if load_data == True:
            self.r = self.read_single_band(band,downsampl=downsampl)

        # Or load just a subset region
        elif isinstance(load_data,tuple) or isinstance(load_data,list):
            if len(load_data) == 4:
                self.r = self.read_single_band_subset(load_data,latlon=latlon,
                    band=band,update_info=True,downsampl=downsampl)

        elif load_data == False:
            return

        else:
            print('Warning : load_data argument not understood. No data loaded.')