classy reclassing
Greg Koerper
greg at bio.cor2.epa.gov
Wed May 27 19:02:11 EDT 1992
Here's a simple shell script that is helpful for streamlining the r.reclass
command when applied to continuous variables. It labels the reclass
categories, which simplifies legend display. It has an offset option that
allows for manipulation of negative values. If you use the -N flag, you can
quickly ascertain how it builds reclass rules. We've used it for post-
processing of model output of continuous variables associated with sites.
-------------------------------shell script ---------------------------------
#! /bin/sh
# reclass.sh takes a single line of input which specifies the beginning
# range of each of a series of range intervals that are then passed to
# r.reclass as input. The units_abbrev is helpful in outputting a legend.
# Use offset if the cell file data are all positive but in fact may represent
# negative values (useful in avoiding "no data" designations for real 0
# values).
# comments, concerns to greg at bio.cor2.epa.gov
# if -N flag, raster is not created and input to r.reclass is
# stored under given file_name
# if -c flag, next argument specifies color rules for reclassification
# see r.colors (incompatible with -N)
USAGE="$0 [-N | -c color_rules] file units_abbrev [offset] [< input]"
RASTER="YES"
COLORS=''
if [ $# -eq 0 -o $# -gt 5 ]
then
echo $USAGE
exit -1
fi
# continue only if user is executing GRASS
if [ "$GISRC" = "" ]
then
echo "Sorry, you are not running GRASS" >&2
exit 4
else
USERGRASS="$GISDBASE/$LOCATION_NAME/$MAPSET"
fi
if [ $1 = "-N" ]
then
RASTER="NO"
shift
RULES=$1
elif [ $1 = "-c" ]
then
COLORS=$2
shift 2
fi
if [ $RASTER = "YES" ]
then
RULES="/tmp/tmp.$$"
FILE=$1
fi
units=$2
cat=`expr 1`
if test $3
then
offset=`expr $3`
else
offset=`expr 0`
fi
read cuts
echo " OK, I'll take it from here . . ."
set -- ${cuts}
start=$1
shift
cp /dev/null $RULES
while test $1
do
RANGE=`echo "${start} thru $1 = ${cat} "`
echo $RANGE`expr $start + $offset` - `expr $1 + $offset` ${units} \
>> $RULES
start=`expr $1 + 1`
shift
cat=`expr $cat + 1`
done
echo "end" >> $RULES
if [ $RASTER = "YES" ]
then [ -s $USERGRASS/colr/$FILE.rec ] && rm $USERGRASS/colr/$FILE.rec
r.reclass input=$FILE output=$FILE.rec < $RULES
rm $RULES
if [ $COLORS ]
then
r.colors map=$FILE.rec color=rules < $COLORS
fi
fi
----------------------------end shell script----------------------------------
greg
******************************************************************************
Greg Koerper Internet: greg at towhee.cor2.epa.gov
ManTech Environmental Technology, Inc. UUCP: hplabs!hp-pcd!orstcs!koerper
200 SW 35th St., JSB
Corvallis, OR 97333 "The 90s will make the 60s look like the 50s.
(503) 754-4490 Just ask your kids."
fax: (503) 754-4338
******************************************************************************
More information about the grass-user
mailing list