[GRASS-dev] [grass-code I][405] r.out.gdal sets NoData wrong

code I item #405, was opened at 2007-05-23 00:27
Status: Open
Priority: 4
Submitted By: Maciej Sieczka (msieczka)
Assigned to: Nobody (None)
Summary: r.out.gdal sets NoData wrong
Issue type: module bug
Issue status: None
GRASS version: CVS HEAD
GRASS component: raster
Operating system: all
Operating system version:
GRASS CVS checkout date, if applies (YYMMDD): 070523

Initial Comment:
r.out.gdal sets NoData wrong. Example, in spearfish60:

$ r.mapcalc 'check=rand(0,256)'

$ r.info -rt check
min=0
max=255
datatype=CELL

$ r.out.gdal check out=check.tif type=Byte
$ r.in.gdal in=check.tif out=check_re
$ r.info -rt check_re
min=0
max=254
datatype=CELL

As you can see rasters "check" and "check_re" have different max values (255 vs 254) while those should be identical. The problem source is that r.out.gdal set 255 to null in "check.tif" by force:

$ gdalinfo -mm check.tif | grep 'NoData\|Min'
    Computed Min/Max=0.000,254.000
  NoData Value=255

As there is no null in original "check" raster, the above should rather read:

    Computed Min/Max=0.000,255.000

and no "NoData".

Note that r.out.gdal.sh is buggy too (or actually the gdal_translate, which it calls), though in a different way:

$ r.out.gdal.sh check out=check.tif type=Byte
$ gdalinfo -mm check.tif | grep 'NoData\|Min'
    Computed Min/Max=0.000,255.000
  NoData Value=256

There should be no NoData, as there is no null in the input GRASS raster. Value 256 is not present in input "check" at all. Moreover, 256 is beyond GDAL's "Byte" value range.

----------------------------------------------------------------------

You can respond by visiting:
http://wald.intevation.org/tracker/?func=detail&atid=204&aid=405&group_id=21

code I item #405, was opened at 2007-05-23 00:27

[cc g-dev]
..

Summary: r.out.gdal sets NoData wrong

..

r.out.gdal sets NoData wrong. Example, in spearfish60:

need to set
  GDALSetRasterNoDataValue(GDALRasterBandH hBand, double dfValue)

http://www.gdal.org/gdal_8h.html#763e876f9b4c3f2b4bae2816af572fd2

"To clear the nodata value, just set it with an "out of range" value."

Note that r.out.gdal.sh is buggy too (or actually the gdal_translate,
which it calls), though in a different way:

$ r.out.gdal.sh check out=check.tif type=Byte
$ gdalinfo -mm check.tif | grep 'NoData\|Min'
    Computed Min/Max=0.000,255.000
  NoData Value=256

There should be no NoData, as there is no null in the input GRASS
raster. Value 256 is not present in input "check" at all. Moreover,
256 is beyond GDAL's "Byte" value range.

The needed gdal_translate option is
       -a_nodata value:
           Assign a specified nodata value to output bands.

Hamish

Hamish Bowman wrote:

Maciej Sieczka wrote:

r.out.gdal sets NoData wrong. Example, in spearfish60:

need to set
GDALSetRasterNoDataValue(GDALRasterBandH hBand, double
dfValue)
http://www.gdal.org/gdal_8h.html#763e876f9b4c3f2b4bae2816af572fd2

"To clear the nodata value, just set it with an "out of
range" value."

Do you mean r.out.gdal needs to do it, or the user?

This is propably what gdal_translate (r.out.gdal.sh) does:

input is 0-255, type=Byte -> NoData=256:

$ r.mapcalc 'check=rand(0,256)'

$ r.info -rt check
min=0
max=255
datatype=CELL

$ r.out.gdal.sh check out=check.tif type=Byte

$ gdalinfo -mm check.tif | grep 'NoData\|Min'
    Computed Min/Max=0.000,255.000
  NoData Value=256

But, this is dirty anyway. I had no null in my input, so why should I
have NoData in the output? Like I wrote:

There should be no NoData, as there is no null in the
input GRASS raster. Value 256 is not present in input
"check" at all. Moreover, 256 is beyond GDAL's "Byte"
value range.

I saw GeoTIFFs without the NoData set, so should be possible in
general. But maybe GRASS raster -> GeoTIFF must have some NoData set
for some reason, ?. An issue in GDAL or GRASS?

The needed gdal_translate option is
      -a_nodata value:
          Assign a specified nodata value to output bands.

What would that help? I don't want NoData in the gdal_transalate
(r.out.gdal.sh) output at all, as there is no null in the input GRASS
raster.

Maciek