4

Does anyone know if it's possible to add a TIFFTAG when saving a TIFF file (I'm using the C/libtiff interface) that will give a name to each band?

Some kind of per-band TIFFTAG_IMAGEDESCRIPTION is what I'm after. I checked the documentation but can't find anything - however, I have seen TIFFs saved with band names so I assume it's possible somehow.

I am not using rasterio.

4
  • I thought this looked like it might be off-topic but since Remote Sensing is on-topic the library being asked about appears to be too: remotesensing.org/libtiff
    – PolyGeo
    Jul 28, 2015 at 11:09
  • I posted here as I've only ever seen per-band names for RS data: Usually a name with the central wavelength of other important feature of the channel.
    – os1
    Jul 29, 2015 at 8:00
  • It sounds to me a bit like a simplified case of Raster Attribute Table (RAT). GDAL seems to support them only for Idrisi, GeoRaster, KEA and HFA (Erdas) formats. However, if TIFFTAG_IMAGEDESCRIPTION is enough for you it can be handled with the GDAL GeoTIFF driver gdal.org/frmt_gtiff.html. Reading the source code can help you with your own programming.
    – user30184
    Jul 29, 2015 at 9:50
  • Thanks, but I'm already using that tifftag. I'm beginning to think that the files I saw with per-band names were using some very software-specific thing. Can't find any more info about them.
    – os1
    Jul 29, 2015 at 19:51

1 Answer 1

0

It is possible to add band descriptions with GDAL and Python.

from osgeo import gdal
file = gdal.Open('test.tif')
band1 = file.GetRasterBand(1)
band2 = file.GetRasterBand(2)
band3 = file.GetRasterBand(3)
band1.SetDescription('description of the first band')
band2.SetDescription('description of the second band')
band3.SetDescription('description of the third band')
del band1
del band2
del band3
del file

Check the result

gdalinfo test.tif
...
Band 1 Block=12000x1 Type=Byte, ColorInterp=Red
  Description = description of the first band
Band 2 Block=12000x1 Type=Byte, ColorInterp=Green
  Description = description of the second band
Band 3 Block=12000x1 Type=Byte, ColorInterp=Blue
  Description = description of the third band

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.