[GRASS-user] sum one raster map conditional on another raster map

I would like to sum all of the positive values of one raster map
(NDVI) based on a raster containing many watersheds that have values
1-22. Is there a way to do this in GRASS? Or a way to export this
information to R and get the same results. I hope this is clear
enough.
thanks,

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                -K. Mullis

stephen sefick wrote:

I would like to sum all of the positive values of one raster map
(NDVI) based on a raster containing many watersheds that have values
1-22. Is there a way to do this in GRASS? Or a way to export this
information to R and get the same results. I hope this is clear
enough.

  r.statistics method=sum ...

This will round the cover values to integers, so you might need to
scale them first.

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

Hello Stephen,

On Mittwoch, 17. März 2010 23:06:55 stephen sefick wrote:

I would like to sum all of the positive values of one raster map
(NDVI) based on a raster containing many watersheds that have values
1-22. Is there a way to do this in GRASS? Or a way to export this

[..]

Glynn already pointed you to r.statistics hence you only need to combine it
with a few if-else statement in r.mapcalc:

r.mapcalc "watershed_new = if(watershed >=1 && watershed <=22,1,0)"
# if watersheds values are larger-equal 1 AND smaller-equal 22, assign value 1
otherwise value 0

r.mapcalc "ndvi_new = if(ndvi_raster >=0,ndvi_raster,null())"
#all values above 0 keep their values, below 0 are converted to null()
(nothing)

r.mapcalc "ndvi_new_clip = if(watershed_new == 1,ndvi_new,null())"
# if watershed_new is equal 1 (see above), then assign the values of ndvi_new,
otherwise nothing

now you can perform the r.statistics method=sum analysis on NDVI values above
0 only and for areas where watershed is above 1 and below 22.

hope this helps and I understood your question right, Martin

P.S.: in case you want to do the analysis on single watersheds (1-22) then you
would need another statement like:
for i in 1 2 3 4 5 ... 22 ; do
r.mapcalc "new = if(watershed == $i,1,null())"
r.statistics ....
; done

--
Dr. Martin Wegmann

University of Wuerzburg
Institute of Geography
Department of Remote Sensing
Remote Sensing and Ecosystem Research
Am Hubland
97074 Wuerzburg, Germany
@
German Aerospace Center (DLR)
German Remote Sensing Data Center (DFD)

Phone: +49-(0)931-31-83446
Fax: +49-(0)931-888-4961
Email: martin.wegmann@uni-wuerzburg.de
url: http://www.remote-sensing.uni-wuerzburg.de
url: http://www.dlr.de/caf
url: http://www.global-change-ecology.de

Martin Wegmann wrote:

P.S.: in case you want to do the analysis on single
watersheds (1-22) then you would need another statement like:

for i in 1 2 3 4 5 ... 22 ; do

power-tool tip o'the day:

for i in `seq 22` ; do
...

or `seq begin end`
or `seq begin step end`
and -s, to comma separate instead of newline.

Hamish