[GRASS5] r.mapcalc question

Paul Kelly paul-grass at stjohnspoint.co.uk
Wed Feb 2 15:37:08 EST 2005


On Wed, 2 Feb 2005, David Piasecki wrote:

> r.mapcalc 
> 'calc.red=if(isnull(image0.red),image1.red,if(isnull(image1.red),image0. 
> red))'
>
> That's great; however, I have 42 images. So I tried some logic...
> r.mapcalc 'calc.red=( image0.red || image1.red )'
> r.mapcalc 'calc.red=( image0.red + image1.red )'
>
> I think these aren't working because GRASS has a problem evaluating these 
> expressions since image0.red is null wherever image1.red is not null. 
> However, no error messages are given. Is there an easier way to do this than 
> the first command given above?

Assuming none of your non-NULL cells have a value of 0, perhaps convert 
all the nulls to 0 using r.null? What you have written probably would have 
worked in GRASS 4 before NULLs were introduced. In GRASS 5, if any of the 
input maps for a cell in r.mapcalc are null then the output cell is null.

Something like
r.null image0.red null=0
r.null image1.red null=0
might do what you want. But your first way is more correct IMHO and 
probably the way it should be done.

Paul




More information about the grass-dev mailing list