2

Can someone tell me what I am doing wrong? I want to set bands 1 and three to 255, and band 2 to 0. The code below only should only set band 2, but gdalinfo shows that all bands get set to 0. Ubuntu 14.04, gdal 1.11.0. Thanks!

--------------------------------------
import sys
import os.path
import gdal

input = sys.argv[1]

dataset = gdal.Open( input, gdal.GA_Update )
if dataset is None:
    print 'Unable to open', input, 'for writing'
    sys.exit(1)    
band = dataset.GetRasterBand(2)
band.SetNoDataValue(0.0)
band.FlushCache()
band = None
dataset = None

----------------------------------------------

$ gdalinfo test.tif
...
Upper Right (-11546254.150, 4881966.253) 
Lower Right (-11546254.150, 4244288.152) 
Center      (-11950987.074, 4563127.202) 
Band 1 Block=15107x1 Type=Byte, ColorInterp=Red
  NoData Value=0
Band 2 Block=15107x1 Type=Byte, ColorInterp=Green
  NoData Value=0
Band 3 Block=15107x1 Type=Byte, ColorInterp=Blue
  NoData Value=0
  • 4
    GeoTiffs only support one no data value for all bands. The GDALData model suggests support for band specific no data, but some (probably many) formats and dataset specific. There is a ticket open in trac: trac.osgeo.org/gdal/ticket/2083 – user10353 Nov 15 '14 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.