[Gdal-dev] wrong nodata returned in GDAL dependent software
Maciej Sieczka
tutey at o2.pl
Fri Jun 15 16:12:33 EDT 2007
Frank Warmerdam wrote:
> Maciej Sieczka wrote:
>> Although my GeoTIFF has a value range 0-255 with nodata set to 256 [1],
>> both QGIS 0.8.1 and OpenEV output '255' when I query the area supposed
>> to be nodata. Any ideas what could be the culprit? I *suspect* the
>> issue might be in GDAL itself, as I can reproduce the problem in two
>> different viewers. Example GeoTiff attached. My specs:
> Your gdalinfo report listed the file as data type Byte. The largest value
> that can be represented in a Byte is 255. So there is no way to read back
> values of 256 from such a file.
>
> If the file was written with GDAL from a buffer bigger than Byte but
> to a file with data type Byte, then GDAL would clamp a value of 256 to
> the maximum representable value, 255, while writing. Perhaps this
> happened?
>
> In any event, it is not meaningful to have a nodata value of 256 for a byte
> data file.
That's what r.out.gdal.sh did, ie. gdal_translate. My raster in GRASS
was 0-255 and had null. "r.out.gdal.sh input=test format=GTiff
type=Byte output=test.tif" created a 0-255 GeoTIFF with nodata set to 256.
So my error was that I should specify at least type=Int16 instead of
Byte to cover the whole range; or Uint16 to preserve the colortable too.
Propably r.out.gdal.sh should yield an appropriate warning for such
cases. I'll try to implement filters for r.out.gdal.sh to inform the
user that the selected file data type can't cover the whole input data
range; if time allows over the weekend.
So all my fault/lack of knowledge. Yet there is something else fishy -
even when the input GRASS raster has no null, still gdal_translate
forces a nodata, eg.:
$ r.mapcalc 'test=rand(0,1024)'
$ r.info -r test
min=0
max=1023
$ r.out.gdal.sh input=test format=GTiff type=UInt16 output=test.tif
$ gdalinfo -mm test.tif | grep 'Computed\|NoData'
Computed Min/Max=0.000,1023.000
NoData Value=65535
Or this one:
$ r.mapcalc 'test=rand(0,256)'
$ r.info -r test
min=0
max=255
$ gdal_translate /gdata/spearfish60/sieczka/cellhd/test test.tif
$ gdalinfo -mm test.tif | grep 'Computed\|NoData'
Computed Min/Max=0.000,255.000
NoData Value=256
Is this OK? In either case I don't have any null in my input 'test'
GRASS raster this time. Why is GDAL forcing it?
Maciek
More information about the Gdal-dev
mailing list