Ticket #2083 (new defect)

Opened 7 months ago

Last modified 7 months ago

gtiff driver not respecting separate nodata for each band

Reported by: maphew Assigned to: warmerdam
Priority: normal Milestone: 1.6.0
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: gtiff
Cc: dron, rouault, mloskot

Description

The geotiff format driver assigns all bands the same nodata value, even if only a single band was specified with bandN.SetNoDataValue Also see http://www.nabble.com/python%3A-setting-nodata-affects-all-bands-td14303097.html

----- gdalsetnull.py -----
import gdal
import sys
import os.path

if len(sys.argv) < 2:
     print "Usage: gdalsetnull.py raster_file null_value"
     sys.exit(1)

input = sys.argv[1]
null_value = sys.argv[2]

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

b1 = dataset.GetRasterBand(1)
b2 = dataset.GetRasterBand(2)
b3 = dataset.GetRasterBand(3)

print 'Initial nodata:\t', b1.GetNoDataValue(), b2.GetNoDataValue(), b3.GetNoDataValue()

b1.SetNoDataValue( float(null_value) )

print 'Output nodata:\t', b1.GetNoDataValue(), b2.GetNoDataValue(), b3.GetNoDataValue()
--------------------------- 

Results:

 python gdalsetnull.py nodata-test.tif 0
Initial nodata: 46.0 46.0 46.0
Output nodata:  0.0 0.0 0.0

Attachments

nodata-test.tif (120.5 kB) - added by maphew on 12/12/07 17:06:05.

Change History

12/12/07 17:06:05 changed by maphew

  • attachment nodata-test.tif added.

12/13/07 09:00:28 changed by dron

  • cc set to dron.

I think it is a good cause to change the way how NODATA handled in TIFFs. We should switch from ASCII representation of the NODATA value to binary one, because ASCII serialization of the floating point values is always error-prone (and actually not necessary).

The new tag definition could look like this:

{ TIFFTAG_GDAL_NODATA_NEW, -2,-2, TIFF_DOUBLE, FIELD_CUSTOM,
  TRUE, FALSE, "GDALNoDataValueNew" }

12/13/07 14:04:39 changed by rouault

-2 means that there's a value for each band, right ? But how do you handle the case where a band has a nodata value, and another one none. Should we decide that a particular value of a double (a NaN for example) means that there's no nodata value for the band ?

12/13/07 14:04:47 changed by rouault

  • cc changed from dron to dron, rouault.

12/13/07 14:29:30 changed by warmerdam

  • keywords set to gtiff.
  • milestone set to 1.6.0.

I would prefer to not try and address this issue before the 1.5 release. It will require changes to the "GDAL nodata tag specification" and I'd rather not do that without due consideration of alternatives and whether the issue is critical enough to justify the disruption.

12/20/07 09:30:14 changed by mloskot

  • cc changed from dron, rouault to dron, rouault, mloskot.