python: setting nodata affects all bands

View: New views
4 Messages — Rating Filter:   Alert me  

python: setting nodata affects all bands

by Matt Wilkie-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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/
--------------------------------------------

_______________________________________________
gdal-dev mailing list
gdal-dev@...
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: python: setting nodata affects all bands

by Frank Warmerdam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matt Wilkie wrote:

> 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.

Matt,

Conceptually each band has a distinct no data value.  However, in
practice, some drivers assume a common nodata value for all bands.  Was
this possibly a geotiff file you were operating on?  This could be
construed as a bug or at least a deficiency of the format driver you
were using.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org

_______________________________________________
gdal-dev mailing list
gdal-dev@...
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: python: setting nodata affects all bands

by Matt Wilkie-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Conceptually each band has a distinct no data value.  However, in
> practice, some drivers assume a common nodata value for all bands.  Was
> this possibly a geotiff file you were operating on?  This could be
> construed as a bug or at least a deficiency of the format driver you
> were using.

Yes it was a geotiff; 3 band RGB. I'll create a bug ticket.

I've also run into trouble trying to clear the nodata value. The doc[0],
if I'm reading the right one, says 'To clear the nodata value, just set
it with an "out of range" value.', but what is an out of range value?

[0]
http://www.gdal.org/classGDALRasterBand.html#c6f081d253dee55c372e54cfdd8f05a6


--
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/
--------------------------------------------

_______________________________________________
gdal-dev mailing list
gdal-dev@...
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: python: setting nodata affects all bands

by Matt Wilkie-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Yes it was a geotiff; 3 band RGB. I'll create a bug ticket.

"gtiff driver not respecting separate nodata for each band"
http://trac.osgeo.org/gdal/ticket/2083


--
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/
--------------------------------------------

_______________________________________________
gdal-dev mailing list
gdal-dev@...
http://lists.osgeo.org/mailman/listinfo/gdal-dev
LightInTheBox - Buy quality products at wholesale price