[GRASS-user] map algebra: sums including null values

Hi,

I’ve just started using GRASS and QGIS. I’m using r.mapcalculator to sum groups of partially overlapping rasterized polygons, with value 1 inside and null outside the polygons. I want each pixel in the output (sum) map to have the value of the number of polygons overlapping at that point, so I’m just summing them up (A+B+C…). The problem is that the sum is only performed where all polygons overlap: if there is a null value at one site, the resulting sum is null… Is there a way to tell GRASS to consider null values as zeroes when performing the sum? Or do I really have to transform null cells into zero-value cells in all rasters before summing them up? (It’s a lot of maps…)

I’d appreciate some help. Cheers,
Marcia


A. Márcia Barbosa
Dept. Biological Sciences, North 2.1
Imperial College at Silwood Park
Ascot, Berkshire SL5 7PY
United Kingdom

Marcia:

I've just started using GRASS and QGIS. I'm using
r.mapcalculator to sum groups of partially overlapping
rasterized polygons, with value 1 inside and null outside
the polygons. I want each pixel in the output (sum) map to
have the value of the number of polygons overlapping at
that point, so I'm just summing them up (A+B+C...). The
problem is that the sum is only performed where all polygons
overlap: if there is a null value at one site, the resulting
sum is null... Is there a way to tell GRASS to consider null
values as zeroes when performing the sum? Or do I really
have to transform null cells into zero-value cells in all
rasters before summing them up? (It's a lot of maps...)

maybe try "r.series method=sum"? (without the -n flag)

with r.mapcalc you can create something with isnull(), but it gets complicated. See the large "NULL support" section in the r.mapcalc help page for examples.

Hamish

Hi Marcia,

it should work with:

r.mapcalc
X=if(isnull(A), 0, A) + if(isnull(B), 0, B) + if(isnull(C), 0, C) ...

Hope it'll help you,

Tim

----- Original Nachricht ----
Von: "Barbosa, A. Marcia" <a.m.barbosa@imperial.ac.uk>
An: grass-user@lists.osgeo.org
Datum: 13.06.2008 12:46
Betreff: [GRASS-user] map algebra: sums including null values

Hi,

I've just started using GRASS and QGIS. I'm using r.mapcalculator to sum
groups of partially overlapping rasterized polygons, with value 1 inside and
null outside the polygons. I want each pixel in the output (sum) map to have
the value of the number of polygons overlapping at that point, so I'm just
summing them up (A+B+C...). The problem is that the sum is only performed
where all polygons overlap: if there is a null value at one site, the
resulting sum is null... Is there a way to tell GRASS to consider null
values as zeroes when performing the sum? Or do I really have to transform
null cells into zero-value cells in all rasters before summing them up?
(It's a lot of maps...)

I'd appreciate some help. Cheers,
Marcia

- - -
A. Márcia Barbosa
Dept. Biological Sciences, North 2.1
Imperial College at Silwood Park
Ascot, Berkshire SL5 7PY
United Kingdom

--------------------------------

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user