[GRASS5] r.statistics workaround for "min" and "max"

Crudeli crudeli at mail.nauta.it
Sun Mar 3 18:02:26 EST 2002


Also
 
r.statistics method=min
 and
r.statistics method=max

seems to work only for the first category of a map.
I'm working with a landuse map and a DSM (as cover). 

r.statistics  base=landuse cover=dsm method=min output=landuse.height

produces a map with the min of a single landuse type (the one with 
category "1").
To produce the map containing all the landuse types, I have to loop 
r.statistics for i from 1 to the category count of the basemap deleting 
the (i-1)-th category from the basemap at every step.
It takes quite long for the maps with hundreds of categories, but at 
least it works.

Make a file of it and chmod it to use.
Hopefully useful for someone else.

Bye,

RafDouglas Candidi Tommasi Crudeli


________________________ ________________________ ________________________

#!/bin/bash

# change the following two lines to match your names.

basemap=NameOfYourBaseMap
DSM=NameOfYourCoverMap

g.region -a $basemap

# this is to work with a map we don't care if it's altered:

r.mapcalc "TheMask=$basemap"

# we find out the maximum number of cats we have in the map
# My basemap originates from "v.alabel -i", so in my case
# NofCat=maximum number of cats=number of cats.
# Anyway, if there are some unused cats, it shouldn't be a problem

NofCat=$(r.info TheMask|grep Range|awk -F "=" '{print $3}'|sed 's/ 
*\||*\| *//g')

j=$[$NofCat]
i=1

# this cicle of r.statistics is done with the nubmer of the _first_ 
category
# increasing at every step. 

let j+=1
until [ $i = $j ];
  do
     echo "cycle $i of $j"
     r.statistics cover=$DSM base=TheMask method=min output=tempstat
     r.mapcalc 
"$landuse.height=if((isnull(@tempstat)),$landuse.height, at tempstat)"

     # the next line nullifies  all the cells in 
     # TheMask whose value is lower than $i
     r.mapcalc "TheMask=if($basemap<=$i,null(),$basemap)"

     let i+=1
  done

g.remove rast=tempstat
g.remove rast=TheMask
d.rast $landuse.height

________________________ ________________________ ________________________




__________________________________________
RafDouglas Candidi Tommasi Crudeli

ct at ehleng.com

"To know, to will, to dare, to be silent."





More information about the grass-dev mailing list