def read_naip(file_path, bands_to_use):
"""
Read in a NAIP, based on www.machinalis.com/blog/python-for-geospatial-data-processing.
Bands_to_use is an array like [0,0,0,1], designating whether to use each band (R, G, B, IR).
"""
raster_dataset = gdal.Open(file_path, gdal.GA_ReadOnly)
bands_data = []
index = 0
for b in range(1, raster_dataset.RasterCount + 1):
band = raster_dataset.GetRasterBand(b)
if bands_to_use[index] == 1:
bands_data.append(band.ReadAsArray())
index += 1
bands_data = numpy.dstack(bands_data)
return raster_dataset, bands_data
评论列表
文章目录