[GRASS-user] r.out.gdal to AAIGrid

Hi,

I’m using r.out.gdal to export raster data from GRASS to Arc/Info ASCII Grid format, to use in another software (Farsite).

However, the resulting ASCII files does not have the NODATA_value parameter in the header.

I’ve tried gdal_translate and it creates, by default, NODATA_value -999

Shouldn’t GRASS also create NODATA_valeu in the header file?

Thank you very much!

Best regards,

Pedro Venâncio

On Aug 3, 2017, at 12:24 PM, Pedro Venâncio <pedrongvenancio@gmail.com> wrote:

I'm using r.out.gdal to export raster data from GRASS to Arc/Info ASCII Grid format, to use in another software (Farsite).

However, the resulting ASCII files does not have the NODATA_value parameter in the header.

I've tried gdal_translate and it creates, by default, NODATA_value -999

Shouldn't GRASS also create NODATA_valeu in the header file?

Hi Pedro,

Have you tried using the nodata parameter?

r.out.gdal nodata=-999 input=yourFile output=yourFileOutput

Best,

Jeshua Lacock
Founder/Engineer
<3DTOPO.com>
GlassPrinted.com

Hi Jeshua,

You’re completely right! I’d tried it, but it gaves me an error, and I did not read it correctly, but it clearly it said that it was not possible to assign that nodata value, because of the selected datatype!

Thank you very much for the hint! And sorry for the noise!

Best regards,
Pedro Venâncio

···

2017-08-04 0:22 GMT+01:00 Jeshua Lacock <jeshua@3dtopo.com>:

On Aug 3, 2017, at 12:24 PM, Pedro Venâncio <pedrongvenancio@gmail.com> wrote:

I’m using r.out.gdal to export raster data from GRASS to Arc/Info ASCII Grid format, to use in another software (Farsite).

However, the resulting ASCII files does not have the NODATA_value parameter in the header.

I’ve tried gdal_translate and it creates, by default, NODATA_value -999

Shouldn’t GRASS also create NODATA_valeu in the header file?

Hi Pedro,

Have you tried using the nodata parameter?

r.out.gdal nodata=-999 input=yourFile output=yourFileOutput

Best,

Jeshua Lacock
Founder/Engineer
<3DTOPO.com>
GlassPrinted.com

Hi Pedro,

I created a test case with the North Carolina sample dataset (by
zooming in the GUI to the elevation map border and setting that as
computational region):

# GRASS 7.2.2svn (nc_spm_08_grass7):~ >

# set computational region around east elevation map border
g.region n=216820 s=216770 w=644960 e=645040 res=10 -p

# be sure that no data pixels are involved.
r.out.ascii input=elevation output=-
north: 216820
south: 216770
east: 645040
west: 644960
rows: 5
cols: 8
101.913734 102.054886 102.395638 102.597229 * * * *
101.821335 102.044083 102.331108 102.58638 * * * *
101.703033 101.955849 102.195648 102.54126 * * * *
101.56945 101.840988 102.152328 102.529175 * * * *
101.530174 101.792572 102.097748 102.477859 * * * *

# export to AAIGrid format:
r.out.gdal input=elevation output=elev.grd format=AAIGrid
Driver <AAIGrid> does not support direct writing. Using MEM driver for
intermediate dataset.
Checking GDAL data type and nodata value...
100%
Using GDAL data type <Float32>
Input raster map contains cells with NULL-value (no-data). The value -nan
will be used to represent no-data values in the input map. You can specify
a nodata value with the nodata option.
Exporting raster data to AAIGrid format...
100%
r.out.gdal complete. File <elev.grd> created.

# verification:
cat elev.grd
ncols 8
nrows 5
xllcorner 644960.000000000000
yllcorner 216770.000000000000
cellsize 10.000000000000
NODATA_value -nan
101.91373443603515625 102.0548858642578125 102.39563751220703125
102.59722900390625 -nan -nan -nan -nan
101.8213348388671875 102.0440826416015625 102.33110809326171875
102.5863800048828125 -nan -nan -nan -nan
101.703033447265625 101.95584869384765625 102.195648193359375
102.541259765625 -nan -nan -nan -nan
101.56945037841796875 101.8409881591796875 102.1523284912109375
102.5291748046875 -nan -nan -nan -nan
101.53017425537109375 101.792572021484375 102.097747802734375
102.4778594970703125 -nan -nan -nan -nan

... all fine and it works out of the box!
Are you sure that you had any NULL cells at all? Note that the current
computational region is respected for export.

Markus

Hi Markus,

You are also completely right! Some of data I exported (elevation, slope, aspect) did not have NULL cells. And in the other data that have NULLs, I used r.null to ensure that the NULL value was -9999. With that I simply transformed the NULL cells to the value -9999, wich are exported as a value and not as a NULL.

I see now that the GRASS behaviour is the correct, because it uses NODATA_value when the input raster contains cells with NULL value, and omits that parameter when the input raster does not contain any NULL cell.

I was somehow mistaken because it seems that other software use NODATA_value as a default parameter, and for instance Farsite and FlamMap, where I use the data exported from GRASS, did not work well without the NODATA_value in the ASCII files, even if the input data has no NULL cells.

Thank you very much!

Best regards,
Pedro

···

2017-08-04 9:52 GMT+01:00 Markus Neteler <neteler@osgeo.org>:

Hi Pedro,

I created a test case with the North Carolina sample dataset (by
zooming in the GUI to the elevation map border and setting that as
computational region):

GRASS 7.2.2svn (nc_spm_08_grass7):~ >

set computational region around east elevation map border

g.region n=216820 s=216770 w=644960 e=645040 res=10 -p

be sure that no data pixels are involved.

r.out.ascii input=elevation output=-
north: 216820
south: 216770
east: 645040
west: 644960
rows: 5
cols: 8
101.913734 102.054886 102.395638 102.597229 * * * *
101.821335 102.044083 102.331108 102.58638 * * * *
101.703033 101.955849 102.195648 102.54126 * * * *
101.56945 101.840988 102.152328 102.529175 * * * *
101.530174 101.792572 102.097748 102.477859 * * * *

export to AAIGrid format:

r.out.gdal input=elevation output=elev.grd format=AAIGrid
Driver does not support direct writing. Using MEM driver for
intermediate dataset.
Checking GDAL data type and nodata value…
100%
Using GDAL data type
Input raster map contains cells with NULL-value (no-data). The value -nan
will be used to represent no-data values in the input map. You can specify
a nodata value with the nodata option.
Exporting raster data to AAIGrid format…
100%
r.out.gdal complete. File <elev.grd> created.

verification:

cat elev.grd
ncols 8
nrows 5
xllcorner 644960.000000000000
yllcorner 216770.000000000000
cellsize 10.000000000000
NODATA_value -nan
101.91373443603515625 102.0548858642578125 102.39563751220703125
102.59722900390625 -nan -nan -nan -nan
101.8213348388671875 102.0440826416015625 102.33110809326171875
102.5863800048828125 -nan -nan -nan -nan
101.703033447265625 101.95584869384765625 102.195648193359375
102.541259765625 -nan -nan -nan -nan
101.56945037841796875 101.8409881591796875 102.1523284912109375
102.5291748046875 -nan -nan -nan -nan
101.53017425537109375 101.792572021484375 102.097747802734375
102.4778594970703125 -nan -nan -nan -nan

… all fine and it works out of the box!
Are you sure that you had any NULL cells at all? Note that the current
computational region is respected for export.

Markus