[GIS] Creating a multi-band GeoTIFF

gdallandsatmulti-bandpythonraster

I followed the instructions here. My input layers are 7 .tif images, each representing a spectral band of a Landsat image. I'm attempting to extract these bands using GDAL:

raster_dataset = gdal.Open(raster_data_path, gdal.GA_ReadOnly)

bands_data = []
for b in range(1, raster_dataset.RasterCount+1):
    band = raster_dataset.GetRasterBand(b)
    bands_data.append(band.ReadAsArray())

Issue is, raster_dataset.RasterCount == 1 and I'm getting arrays full of zeros.

Best Answer

I do it exactly as you've written it, here's my production code:

for band_n in range(n_parameters):
    band = ds.GetRasterBand(band_n + 1)
    band_array = band.ReadAsArray()
    all_data[band_n] = band_array

So I don't think there's an issue with this code.

I'd check your source files in something like QGIS, where you can view the data and ensure that it's correct in the files.

Also, you mention you have 7 files, so don't you need to loop over each file rather than through bands in one file?