python gdal ReadAsArray 按块读取栅格

gdal ReadAsArray支持按块读取影像,有两种方式:

(1)针对dataset

dataset = gdal.Open(file, gdal.GA_ReadOnly)
data = dataset.ReadAsArray(xoff=0, yoff=0, xsize=512, ysize=512)

(2)针对band

dataset = gdal.Open(file, gdal.GA_ReadOnly)
band = dataset.GetBand(0)
data = band.ReadAsArray(xoff=0, yoff=0, win_xsize=512, win_ysize=512)

注意:dataset和band模式中参数不同xsize和win_xsize

ReadAsArray定义:

# dataset.ReadAsArray
def ReadAsArray(self, xoff=0, yoff=0, xsize=None, ysize=None, buf_obj=None,
                    buf_xsize = None, buf_ysize = None, buf_type = None,
                    resample_alg = GRIORA_NearestNeighbour,
                    callback = None,
                    callback_data = None):
""" Reading a chunk of a GDAL band into a numpy array. The optional (buf_xsize,buf_ysize,buf_type) parameters should generally not be specified if buf_obj is specified. The array is returned"""


# band.ReadAsArray
def ReadAsArray(self, xoff=0, yoff=0, win_xsize=None, win_ysize=None,
                    buf_xsize=None, buf_ysize=None, buf_type=None, buf_obj=None,
                    resample_alg = GRIORA_NearestNeighbour,
                    callback = None,
                    callback_data = None):
""" Reading a chunk of a GDAL band into a numpy array. The optional (buf_xsize,buf_ysize,buf_type) parameters should generally not be specified if buf_obj is specified. The array is returned"""

r

你可能感兴趣的:(Python,Earth,Observation)