def __init__(self,ds_filename,load_data=True,latlon=True,band=1,
spatial_ref=None,geo_transform=None,downsampl=1):
""" Construct object with raster from a single band dataset.
Parameters:
ds_filename : filename of the dataset to import
load_data : - True, to import the data into obj.r.
- False, to not load any data.
- tuple (left, right, bottom, top) to load subset;
obj.extent will be set to reflect subset area.
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.')
评论列表
文章目录