[GRASSLIST:3552] r.maximum

crudeli crudeli at mail.nauta.it
Sat Apr 20 15:22:05 EDT 2002


Dear GRASS users,

I wrote this little script to perform a task similar to r.average and r.median.
this command takes three arguments: base cover output and writes a 
raster map "output" containing the maximum values found on the 
"cover" map for every different "base" value.

Copy this script to a file called r.maximum (or whatever you like) and

chmod a+x r.maximum

Invocation is

r.maximum  base cover output

Hope you find this useful.
Regards,
Raffaele Douglas Candidi Tommasi Crudeli

__________________
#!/bin/bash

if [ -z "$1" ] || [ -z "$2" ] || [ -z $3 ]; then
     echo
     echo Usage: $0 base cover output
     echo
     exit
fi

if [ ! -f $LOCATION"/cell/$1" ]; then
     echo
     echo "Filename $1 not found"
     echo
     exit
fi

if [ ! -f $LOCATION"/cell/$2" ]; then
     echo
     echo "Filename $2 not found"
     echo
     exit
fi

r.stats -1Cn input=$1,$2|sort -n|awk '
BEGIN {
min=10000000
max=-10000000
cat=1
}

{
if ($1==cat) {
if ($2 < min) {
min=$2
}
if ($2 >max) {
max=$2
}
}else{
printf ("%s %f %f\n",cat,min,max)
#printf ("%s:%s:%f\n",cat,cat,min)
#printf ("%s=%f\n",cat,min)
cat=$1
min=10000000
max=-10000000
}

}

END {
printf ("%s %f %f\n",cat,min,max)
#printf ("%s:%s:%f\n",cat,cat,min)
  }
'|r.recode -a input=$1 output=$3



More information about the grass-user mailing list