本文整理匯總了Python中osgeo.gdal.GetDataTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Python gdal.GetDataTypeName方法的具體用法?Python gdal.GetDataTypeName怎麽用?Python gdal.GetDataTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類osgeo.gdal
的用法示例。
在下文中一共展示了gdal.GetDataTypeName方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: GetGeoInfo
# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDataTypeName [as 別名]
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:
示例2: get_reference_water_data
# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDataTypeName [as 別名]
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
示例3: GetGeoInfo
# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDataTypeName [as 別名]
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
示例4: get_geo_info
# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDataTypeName [as 別名]
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
示例5: get_bil_data
# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDataTypeName [as 別名]
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
#
示例6: _fromGDAL
# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDataTypeName [as 別名]
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
#######################################
示例7: __init__
# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDataTypeName [as 別名]
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.')