[GRASS-dev] gdal import an nodata cells

I just imported a DEM that was sent to to in Erdas IMG format (HFA),
with r.in.gdal, and after importing I had to use r.mapcalc to make the
NODATA cells -- which were tagged as -32768 -- became NULL.

I was just wondering if there is a way to do this automatically? can I
pass the -32768 value as an option to r.in.gdal so the cell will be
imported as null?

cheers

Carlos

--
+-----------------------------------------------------------+
              Carlos Henrique Grohmann - Guano
  Visiting Researcher at Kingston University London - UK
  Geologist M.Sc - Doctorate Student at IGc-USP - Brazil
Linux User #89721 - carlos dot grohmann at gmail dot com
+-----------------------------------------------------------+
_________________
"Good morning, doctors. I have taken the liberty of removing Windows
95 from my hard drive."
--The winning entry in a "What were HAL's first words" contest judged
by 2001: A SPACE ODYSSEY creator Arthur C. Clarke

Carlos "Guâno" Grohmann schrieb:

I just imported a DEM that was sent to to in Erdas IMG format (HFA),
with r.in.gdal, and after importing I had to use r.mapcalc to make the
NODATA cells -- which were tagged as -32768 -- became NULL.

I was just wondering if there is a way to do this automatically? can I
pass the -32768 value as an option to r.in.gdal so the cell will be
imported as null?

cheers

Carlos

you can use r.null to set the null flag.

Yes, but I was thinking how to do this _at once_ ,in the import process.

C

On 7/19/07, WolfgangZ <wollez@gmx.net> wrote:

Carlos "Guâno" Grohmann schrieb:
> I just imported a DEM that was sent to to in Erdas IMG format (HFA),
> with r.in.gdal, and after importing I had to use r.mapcalc to make the
> NODATA cells -- which were tagged as -32768 -- became NULL.
>
> I was just wondering if there is a way to do this automatically? can I
> pass the -32768 value as an option to r.in.gdal so the cell will be
> imported as null?
>
> cheers
>
> Carlos
>

you can use r.null to set the null flag.

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
+-----------------------------------------------------------+
              Carlos Henrique Grohmann - Guano
  Visiting Researcher at Kingston University London - UK
  Geologist M.Sc - Doctorate Student at IGc-USP - Brazil
Linux User #89721 - carlos dot grohmann at gmail dot com
+-----------------------------------------------------------+
_________________
"Good morning, doctors. I have taken the liberty of removing Windows
95 from my hard drive."
--The winning entry in a "What were HAL's first words" contest judged
by 2001: A SPACE ODYSSEY creator Arthur C. Clarke

Hi,

I am not sure if make sense to add 'null' parameter to r.in.gdal. You
can use r.null...

Martin

2007/7/19, Carlos Guâno Grohmann <carlos.grohmann@gmail.com>:

Yes, but I was thinking how to do this _at once_ ,in the import process.

C

On 7/19/07, WolfgangZ <wollez@gmx.net> wrote:
> Carlos "Guâno" Grohmann schrieb:
> > I just imported a DEM that was sent to to in Erdas IMG format (HFA),
> > with r.in.gdal, and after importing I had to use r.mapcalc to make the
> > NODATA cells -- which were tagged as -32768 -- became NULL.
> >
> > I was just wondering if there is a way to do this automatically? can I
> > pass the -32768 value as an option to r.in.gdal so the cell will be
> > imported as null?
> >
> > cheers
> >
> > Carlos
> >
>
> you can use r.null to set the null flag.
>
> _______________________________________________
> grass-dev mailing list
> grass-dev@grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass-dev
>

--
+-----------------------------------------------------------+
              Carlos Henrique Grohmann - Guano
  Visiting Researcher at Kingston University London - UK
  Geologist M.Sc - Doctorate Student at IGc-USP - Brazil
Linux User #89721 - carlos dot grohmann at gmail dot com
+-----------------------------------------------------------+
_________________
"Good morning, doctors. I have taken the liberty of removing Windows
95 from my hard drive."
--The winning entry in a "What were HAL's first words" contest judged
by 2001: A SPACE ODYSSEY creator Arthur C. Clarke

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Carlos "Guâno" Grohmann wrote:

I just imported a DEM that was sent to to in Erdas IMG format (HFA),
with r.in.gdal, and after importing I had to use r.mapcalc to make the
NODATA cells -- which were tagged as -32768 -- became NULL.

I was just wondering if there is a way to do this automatically? can I
pass the -32768 value as an option to r.in.gdal so the cell will be
imported as null?

Carlos,

I don't see any options to provide a nodata on the r.in.gdal commandline,
but r.in.gdal will set pixels to null if GDAL "knows" the nodata value for
the source dataset. Nodata support does exist now in the HFA (.img) driver
but I think it was recently introduced. It is also possible that the nodata
value wasn't properly marked in the source .img file.

A commandline argument for this could be added to r.in.gdal, but given the
relative ease of fixing it up with r.mapcalc, I'm not sure it would be
worth the complication.

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

thnak you.

If the programming, of GRASS, is integer-centric, why not solve the null-difficulty with invisible ( ; ) c programming-style work - as, at a similar time in the computer-service world, that was the a vs 1 (text v nt) solution?
:slight_smile:

-----Original Message-----
From: grassuser-bounces@grass.itc.it [mailto:grassuser-bounces@grass.itc.it] On Behalf Of Frank Warmerdam
Sent: Thursday, July 19, 2007 8:42 AM
To: "Carlos \"Guâno\" Grohmann"
Cc: GRASS List
Subject: [GRASS-user] Re: [GRASS-dev] gdal import an nodata cells

Carlos "Guâno" Grohmann wrote:

I just imported a DEM that was sent to to in Erdas IMG format (HFA),
with r.in.gdal, and after importing I had to use r.mapcalc to make the
NODATA cells -- which were tagged as -32768 -- became NULL.

I was just wondering if there is a way to do this automatically? can I
pass the -32768 value as an option to r.in.gdal so the cell will be
imported as null?

Carlos,

I don't see any options to provide a nodata on the r.in.gdal commandline, but r.in.gdal will set pixels to null if GDAL "knows" the nodata value for the source dataset. Nodata support does exist now in the HFA (.img) driver but I think it was recently introduced. It is also possible that the nodata value wasn't properly marked in the source .img file.

A commandline argument for this could be added to r.in.gdal, but given the relative ease of fixing it up with r.mapcalc, I'm not sure it would be worth the complication.

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

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

Carlos "Guâno" Grohmann wrote:
> I just imported a DEM that was sent to to in Erdas IMG format (HFA),
> with r.in.gdal, and after importing I had to use r.mapcalc to make
> the NODATA cells -- which were tagged as -32768 -- became NULL.
>
> I was just wondering if there is a way to do this automatically? can
> I pass the -32768 value as an option to r.in.gdal so the cell will
> be imported as null?

Frank Warmerdam wrote:

I don't see any options to provide a nodata on the r.in.gdal
commandline, but r.in.gdal will set pixels to null if GDAL "knows" the
nodata value for the source dataset. Nodata support does exist now in
the HFA (.img) driver but I think it was recently introduced. It is
also possible that the nodata value wasn't properly marked in the
source .img file.

A commandline argument for this could be added to r.in.gdal, but given
the relative ease of fixing it up with r.mapcalc, I'm not sure it
would be worth the complication.

see also r.out.gdal's createopt= option and gdal_translate's -a_nodata
option for setting the no data value.

does gdalinfo show the nodata value? (I'm not sure if it should or not)

Hamish

gdalinfo will show the nodata value if the file format supports storing the value in the header. So, for surfer, DTED, USGSDEM and such it indicates what the nodata value is but not for GeoTiff, IMA and such.

does gdalinfo show the nodata value? (I'm not sure if it should or not)

Mike

Ops... Looks like Geotiff does allow for storing no-data values. But HFA (not too sure which format IMA is) and others don't appear too.

Question?

is float(nan) equal to double(nan)? If not, does gdal_translate understand this when it converts a file stored as float64 to float32? gdal_translate allows one to define what the no-data value is, but how do I tell it to change the input no-data value to a different output no-data value? IE, the no-data value in my surfer file is a double precision nan, but I want the no-data value in my output GeoTiff (float32) to be -32767. -a_nodata changes the header no-data definition but does not change the values of the pixels that represent no-data.

Sorry, It's not really a grass question but I thought I'd ask since were on the topic and it's currently giving me headaches.

Cheers,

Mike

On 19-Jul-07, at 7:45 PM, Michael Perdue wrote:

gdalinfo will show the nodata value if the file format supports storing the value in the header. So, for surfer, DTED, USGSDEM and such it indicates what the nodata value is but not for GeoTiff, IMA and such.

does gdalinfo show the nodata value? (I'm not sure if it should or not)

Mike

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

Michael Perdue wrote:

Ops... Looks like Geotiff does allow for storing no-data values. But HFA (not too sure which format IMA is) and others don't appear too.

Michael,

Note that GeoTIFF does not *generally* support nodata values, but there is
a GDAL specific tag used by GDAL and GDAL based software to keep track of
nodata values.

Question?

is float(nan) equal to double(nan)?

They are not the same as the binary level of course. I don't know if
they compare as equal in C or not. Hopefully they do.

However, GDAL does *not* generally recognise NaN as a nodata value.

> If not, does gdal_translate

understand this when it converts a file stored as float64 to float32? gdal_translate allows one to define what the no-data value is, but how do I tell it to change the input no-data value to a different output no-data value? IE, the no-data value in my surfer file is a double precision nan, but I want the no-data value in my output GeoTiff (float32) to be -32767. -a_nodata changes the header no-data definition but does not change the values of the pixels that represent no-data.

I'm not aware of a practical way of doing this. Sorry.
You are likely best off fixing this up in GRASS which is more
flexible.

(BTW, GDAL does support double precision geotiff files)

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

Michael Perdue wrote:

is float(nan) equal to double(nan)?

NaN isn't equal to anything, not even to itself:

  $ cat foo.c
  #include <stdio.h>
  int main(void)
  {
    double nan = 0.0/0.0;
    if (nan == nan)
      printf("equal\n");
    else
      printf("unequal\n");
    return 0;
  }
  $ gcc -Wall foo.c
  $ ./a.out
  unequal

--
Glynn Clements <glynn@gclements.plus.com>

Michael Perdue wrote:

> If not, does gdal_translate understand this when it converts a file
> stored as float64 to float32? gdal_translate allows one to define
> what the no-data value is, but how do I tell it to change the input
> no-data value to a different output no-data value? IE, the no-data
> value in my surfer file is a double precision nan, but I want the
> no-data value in my output GeoTiff (float32) to be -32767. -a_nodata
> changes the header no-data definition but does not change the values
> of the pixels that represent no-data.

Frank wrote:

I'm not aware of a practical way of doing this. Sorry.
You are likely best off fixing this up in GRASS which is more
flexible.

If it's a corner case, running r.null after r.in.gdal is preferable.

If this is likely to be a common need, a new option could be added to
r.in.gdal for it.

aka send a patch or wait for a devel to be bugged by it too. If you
feel the feature really should be in r.in.gdal, please file a code
request wish for it in the bug tracker and maybe someone will take it
up.

Hamish