I am writing numpy arrays out as ENVI images using gdal in python. Until today, I always accessed the header the hard way by reading in all lines, changing some information and writing it out again. This is not only coding intensive, but also yields multiple error sources.

A better solution would be by using SetMetadata. I tried:

myArray = np.full(shape=(4,3), fill_value=10)

driver = gdal.GetDriverByName('ENVI')
destination = driver.Create("test.bsq", ncols, nrows, 1, gdal.GDT_Float32)
destination.SetMetadataItem('band names', 'band hello world', 'ENVI')

but in the output file, the band is still called "band 1". Is my information overwritten by the built-in function for header creation?

Or maybe I have to set the name for each band individually like

b = destination.GetRasterBand(1)
b.SetBandName("band hello world")

But "SetBandName" does not exist and I cannot find how else it is supposed to be called.

How do I supply band names for ENVI-images then?

1 Answer 1


You need to use the SetDescription method of the raster band object.

rb = destination.GetRasterBand(1)
rb.SetDescription('band hello world')

$ cat /tmp/test.hdr 
description = {
samples = 3
lines   = 4
bands   = 1
header offset = 0
file type = ENVI Standard
data type = 4
interleave = bsq
byte order = 0
band names = {
band hello world}
  • Incredible! I thought "SetDescription" sets the .... description. Man, you cannot make this up...seriously! Well, thank you so much! Commented Jul 18, 2017 at 9:13

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.