I want to write a raster file (using GDAL+Python) with multiple bands. However, I do not know how to name the bands. Their names are always "Band 1", "Band 2", etc. I searched and found a function that should do the trick but failed (SetRasterCategoryNames). I hope that someone could help me how to name when writing multiple-layer rasters in python.

Following code is just an example of writing multiple bands to a raster.

        from osgeo import gdal

        #Read projection information from original raster
        path = '/home/12101008/MCD43A1.A2007001.h26v06.006.2016111212159.hdf'
        GRID_NAME = 'MOD_Grid_BRDF'
        DATAFIELD_NAME = 'BRDF_Albedo_Band_Mandatory_Quality_Band1'    
        gname = 'HDF4_EOS:EOS_GRID:"{0}":{1}:{2}'.format(path, GRID_NAME, DATAFIELD_NAME)    
        gdset = gdal.Open(gname)
        cols = gdset.RasterXSize
        rows = gdset.RasterYSize
        geoTransform = gdset.GetGeoTransform()
        proj = gdset.GetProjection() 

        #Read example layer to test  
        result1 = gdset.ReadAsArray()     
        #print geoTransform, proj, cols, rows
        #Setting driver         
        driver = gdal.GetDriverByName('NetCDF')
        #Create new file and set parameters from original raster
        path1 = '/home/12101008/Processed/test.nc'
        outDataset = driver.Create(path1, cols, rows, 6, gdal.GDT_Int16, ['COMPRESS=PACKBITS'])            
        #Write 6 raster from "result" variable
        for i in range(0,6): 
            outBand = outDataset.GetRasterBand(i+1)
            #Attempted to set band name like this but failed
            outBand.WriteArray(result1, 0, 0) 
        gdset = None
        outBand = None
        outDataset = None 

  • Did you figure out the issue? I think SetRasterCategoryNames does not set the band name actually?
    – Matifou
    Jun 22, 2017 at 0:39
  • 4
    Here: stackoverflow.com/questions/32609570/… they suggest: outBand.SetDescription(BandName) I've tried it without error, but still nothing changes when I visualise my geotiff on QGIS. No updated band names. I would greatly appreciate it if someone knows a way (would prefer gdal and python) to change names in a way that QGIS recognises. There are some suggestions here: lists.osgeo.org/pipermail/gdal-dev/2013-October/037321.html about editing a metadata file (which I currently don't have and am not quite
    – Dr. E
    Sep 7, 2018 at 14:24
  • 1
    Using the SetDescription() method as recommended by @Dr.E is what I do and it works fine for me when I visualize it in ArcGIS. Maybe there is a bug with QGIS that is worth reporting.
    – toferkey
    Dec 17, 2020 at 21:39

2 Answers 2


Please refer to the following post - How to edit the metadata for individual bands of a multiband raster, preferably with GDAL?

Call the script like this to set your band names:

    call python3 gdal_set_band_desc.py input_raster.tif 1 "Desired band 1 name" 2 "Desired band 2 name" 3 "Desired band 3 name"

The band names show up correctly in QGIS (tested with version 3.20).

  • I've tried this solution, but, as per the name of the function, it only changes the band description, and not the band name. I can also testify to the fact that this is not a QGIS error, as I am uploading the rasters as assets to GEE and there the band name also stays the same as the original. I've also tried with QGIS plugin Rename Bands, but that also updates only the description. Does someone know how to change the band name?
    – Momchill
    Mar 15 at 15:52

Starting in GDAL 3.9, the band names can be specified when the dataset is created using the BAND_NAMES creation option:

gdal.GetDriverByName("NetCDF").Create("out.nc", 100, 100, 2, options={"BAND_NAMES": "t2m,prate"}    )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.