[GRASS-user] Change NaN to 0 with r.mapcalc(or whatever)?

Glynn Clements glynn at gclements.plus.com
Thu May 22 03:27:03 EDT 2008


Moskovitz, Bob wrote:

> Based on what I read from that link I tried:
> 	r.mapcalc "q50_eh_nonan = if(q50_eh != q50_eh,null(),q50_eh)"
> 
> It assigned nan to 0.  It would be great if r.null can use such a simple trick.

Can you try the following patch (committed to SVN trunk as r31470):

-------------- next part --------------
Index: raster/r.null/mask.c
===================================================================
--- raster/r.null/mask.c	(revision 31458)
+++ raster/r.null/mask.c	(working copy)
@@ -65,5 +65,8 @@
     if (I->inf > 0)
 	return x >= I->high;
 
+    if (I->low != I->low && I->high != I->high)
+        return x != x;
+
     return x >= I->low && x <= I->high;
 }
-------------- next part --------------

It should allow you to use e.g. "r.null ... setnull=nan".

It appears to work, but has only been minimally tested.

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


More information about the grass-user mailing list