[Gdal-dev] gdalwarp and nodata values (float v int)

Frank Warmerdam warmerdam at pobox.com
Fri Jul 14 14:38:18 EDT 2006


Bryan Keith wrote:
> Hello again,
> 
> In the last couple days I've posted some messages regarding the AAIGrid 
> driver reading integers v. floats.  That problem's not quite resolved, 
> but I've done a little testing and found the following peculiarity with 
> how gdalwarp handles nodata values.
> 
> I probably noticed the AAIGrid driver problem because I was using an 
> integer for my nodata value in a floating point grid.  So I decided to 
> test it using a floating point value (which I still haven't done yet). 
> However, I get unexpected results with gdalwarp and non-integer nodata 
> values.
> 
> Consider the following examples.  I start with test.tif 
> (Min/Max=1508.000,3413.000) and use gdalwarp 3 different times with only 
> changing the -dstnodata value.  The first time I use -dstnodata 
> -3.40282e+038 (the same as my -srcnodata) and end up with 
> Min/Max=-340282001837565600000000000000000000000.000,3385.788  Then I 
> use -dstnodata -99999 and get the expected Min/Max=1523.000,3385.788 
> Then I use -dstnodata -99999.1 and get Min/Max=-99999.102,3385.788
> 
> What's going on here?

Bryan,

I believe the problem is that some double precision values can't be
represented exactly as float32 values, and so comparisons fail.  GDAL
generally tries to pass around nodata values as double's, but of course
when they are applied to a float32 channel they will be truncated somewhat.
When the float32 values are cast back to double and compared to the
original double value they don't match.

There are things I can do to avoid some of this.  For instance, the min/max
algorithm could cast the double value to float before comparing it to
the float values from the band.

If you want to isolate particular situations where things are going wrong
and submit a bug report I can work on fixing them.  But generally, if you
are going to work with floating point channels, I would suggest picking a
nodata value that is exactly representable in floating point.  For instance,
I think powers of two would be ok, so -0.5 can be exactly represented.

I hope this helps.

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




More information about the Gdal-dev mailing list