[gdal-dev] python: setting nodata affects all bands
Matt Wilkie
matt.wilkie at gov.yk.ca
Wed Dec 12 15:20:20 EST 2007
Hi Folks,
I'm endeavouring to teach myself a little about pythin and gdal by
working on a python script to set the nodata value on a raster. I've
encountered a puzzling thing and I don't know if this is expected
behaviour or I'm doing something wrong. If set nodata on a single band,
all of the bands are affected. For my current project this doesn't
matter, but it just doesn't seem right to me.
In the script below I expected band 1 to be changed and the others to
remain as they are.
----- 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()
---------------------------
I'm using GDAL 1.5.0b1, FWTools 2.0.3, released 2007/12/10
--
matt wilkie
--------------------------------------------
Geographic Information,
Information Management and Technology,
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------
More information about the gdal-dev
mailing list