r.mapcalc and categories
Susan Huse
sue at ced.berkeley.edu
Wed Jul 21 12:55:22 EDT 1993
> From grass-lists-owner at max.cecer.army.mil Wed Jul 21 09:06:13 1993
> From: ca4 at aixfile1.urz.uni-heidelberg.de (Stefan Jaeger)
> Subject: r.mapcalc and categories
> Sender: grass-lists-owner at max.cecer.army.mil
> Reply-To: grassu-list at max.cecer.army.mil
> To: grassu-list at max.cecer.army.mil
> Date: Wed, 21 Jul 93 12:18:34 CET
> X-Mailer: ELM [version 2.3 PL2]
> Content-Length: 248
>
> Hi,
>
> I used r.mapcalc for the automated production of a classified map with about
> 200 categories. How can I assign category labels to those classes
> without r.support or r.reclass?
>
> Stefan Jaeger
> Dept. of Geography
> University of Heidelberg
> Germany
>
To assign categories you need to append your category labels to the
$LOCATION/cats file. The first four lines will be created automatically
whether you assign labels or not. The remaining lines consist of a
series of lines of the form: #:label, where "#" is the category number
and "label" is the label assigned to that number. To automate the
labeling process you could write a script that prompts the user for
labels and then adds them to the bottom of the cats file.
You can easily incorporate the r.mapcalc along with the labeling process
in one shell script.
For example I created the executable:
#!/bin/sh
catnumber=1
while [ $catnumber ]
do
echo "please enter the category number" > "/dev/tty"
read catnumber < "/dev/tty"
echo "please enter the corresponding label" > "/dev/tty"
read label < "/dev/tty"
echo $catnumber":"$label >> $LOCATION/cats/$1
done
It prompts the user for category numbers and labels and appends them
to the category file specified on the command line. I called the
script writecats. I prompts until receiving a null category number.
It unfortunately prints a bogus final line to the cats file consisting
of only a colon. But that can be fixed by bracketing:
echo $catnumber":"$label >> $LOCATION/cats/$1
with an if statement.
Example of usage:
tahoe{sue}98 % writecats filename
please enter the category number
1
please enter the corresponding label
first
please enter the category number
2
please enter the corresponding label
second
please enter the category number
please enter the corresponding label
Appends the cats file "filename" to:
# 5 categories
Nine County At Risk Map
0.00 0.00 0.00 0.00
1:first
2:second
:
Good luck.
If you need more help with shell scripts email me directly.
sue huse
Univ Calif Berkeley
More information about the grass-user
mailing list