[GRASS-user] Raster addition

Moritz Lennert mlennert at club.worldonline.be
Thu Apr 14 08:15:06 EDT 2011


On 14/04/11 13:54, Martin Album Ytre-Eide wrote:
> Hello.
>
> I am trying to add some raster maps. I thought I could do this in
> r.mapcalc, but "new_map= old_1 + old_2" seems to produce a map where
> the maps overlap and ignoring areas where only on of the maps have
> values.

This is due to the way r.mapcalc handles NULL values. See the man page, 
section NULL support for an explanation.

> I would like to do something similar to "v.overlay
> operator=or".
>
> Anyone who knows how to do this?

It depends on what you want the new map to contain as values. If you 
want to add the value of old_1 to old_2 in places where they overlap, 
one way would be to transform your null values to 0 using r.null null= 
and then applying your formula.

If you just want a (any) value where one of the maps is non-null, then 
you can use if. Something like this (untested):

new_map = if(!isnull(old_1) || !isnull(old_2), 1, null())

which should give you 1 where any of the two contains a value and a NULL 
value elsewhere.

Moritz


More information about the grass-user mailing list