Search code examples
pythongdal

How to find the number of bands in gdal in python?


i'm read tiff data using under code.

ds = 'path' , gdal.GA_ReadOnly)

and i find gdal API, i cna't find to read number of bands.

(ex) i have a 3 bands image, then read number of bands and return 3 in case)

is a any way to find number of bands?


Solution

  • The RasterCount attribute gives the band count. Here's a simple example:

    src_ds = gdal.Open("INPUT.tif")
    if src_ds is not None: 
        print ("band count: " + str(src_ds.RasterCount))