[GRASS5] r.mapcalc question

David Piasecki piasecda at nv.doe.gov
Wed Feb 2 18:23:04 EST 2005


Paul,

You were right. Seems the best plan of action is to do the following:

r.mapcalc calc.red=image0.red	// creates the image with the correct  
region information
r.mapcalc  
'calc.red=if(isnull(calc.red),if(not(isnull(image1.red)),image1.red,if(n 
ot(isnull(image2.red)),image2.red)),calc.red)'   // and so on...  
imageN.red

// do the same for green and blue

r.composite r_map=calc.red g_map=calc.green b_map=calc.blue output=cmap  
   // form an rgb composite image

And now I can do whatever I want with it :)

Perhaps this isn't quite the fastest method, but it works. If anyone  
knows of a more efficient way of doing the same thing, I'd be  
interested in taking suggestions.

Thanks,
David



On Feb 2, 2005, at 12:37 PM, Paul Kelly wrote:

> On Wed, 2 Feb 2005, David Piasecki wrote:
>
>> r.mapcalc  
>> 'calc.red=if(isnull(image0.red),image1.red,if(isnull(image1.red),image 
>> 0. 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