[GRASS5] d.vect.leg
Jachym Cepicky
jachym.cepicky at centrum.cz
Tue May 17 05:50:24 EDT 2005
Hallo developers,
before I rewrite d.legend so it is able to work with vector maps too (and I'm
still not sure, if I ever get it), i wrote a script, based on d.vect.thematic,
which should solve as d.vect.leg. It does the same, as d.rast.leg does too. The
difference from d.vect.thematic is, that this script works with GRASSRGB column
from the database.
Anyone for testing?
Screenshot at http://les-ejk.cz/.../d.vect.leg.png
Jáchym
--
Jachym Cepicky
e-mail: jachym.cepicky at centrum.cz
URL: http://les-ejk.cz
GPG: http://www.fle.czu.cz/~jachym/gnupg_public_key/
-------------- next part --------------
#!/bin/sh
#
############################################################################
#
# MODULE: d.vect.leg
# AUTHOR(S): Jachym Cepicky, Ustav geoinformacnich technologii, MZLU v
# Brne, Czech Rep.
# PURPOSE: Displays legend from database table
# COPYRIGHT: (C) 2005 by the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
#############################################################################
#%Module
#% description: Displays a legend for a vector map layer in the active frame on the graphics monitor.
#%End
#%option
#% key: map
#% type: string
#% gisprompt: old,vector,vector
#% description: Vector map to display legend
#% required : yes
#%end
#%option
#% key: column
#% type: string
#% description: Column to use for thematic display (must be numeric)
#% required : yes
#%end
#%option
#% key: layer
#% type: integer
#% description: Layer to use for thematic display
#% answer: 1
#% required : no
#%end
#%option
#% key: type
#% type: string
#% description: Vector map type
#% options: area,point,centroid,line,boundary
#% answer: area
#% required : yes
#%end
if [ -z $GISBASE ] ; then
echo "You must be in GRASS GIS to run this program."
exit 1
fi
if [ "$1" != "@ARGS_PARSED@" ] ; then
exec g.parser "$0" "$@"
fi
# setting environment, so that awk works properly in all languages
export LC_NUMERIC=C
# create temporary file to hold d.graph commands for legend
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
echo "ERROR: unable to create temporary files" 1>&2
exit 1
fi
cleanup()
{
\rm -f $TMP
}
# what to do in case of user break:
exitprocedure()
{
echo "User break!"
cleanup
exit 1
}
# shell check for user break (signal list: trap -l)
trap "exitprocedure" 2 3 15
table=`v.db.connect $GIS_OPT_map -g | grep -w $GIS_OPT_layer | awk '{print $2}'`
if [ -z "$table" ]
then
echo "No table connected or layer <$GIS_OPT_layer> doesn't exist!"
exit 1
fi
d.frame -e
d.frame -s at=0,100,0,65 frame=left
d.vect -a map=$GIS_OPT_map type=$GIS_OPT_type
d.frame -s at=0,100,65,100 frame=right
heading="$GIS_OPT_map: $GIS_OPT_column"
head_length=`echo $heading | wc -m`;
echo "color black" > $TMP
echo "size 5 2" >>$TMP
echo "move 5 95" >>$TMP
echo "text $heading" >>$TMP
echo "move 5 93" >>$TMP
echo -en "text " >>$TMP
# print underline
for ((i=1; i < $head_length ; i++)); do
echo -n "-" >> $TMP
done
echo "" >>$TMP # new line
echo "size 4.5 1.8" >>$TMP
# layout the legend
step=6
line1=90
line2=88
line3=86
ncats=0;
new_cat=0;
# searching for categories
for line in `echo "SELECT $GIS_OPT_column,GRASSRGB FROM $table"|db.select -c fs=";"`;
do
eval `echo "$line"|sed -e s/^/cat=/|sed -e s/\;/\;\ color=\"/|sed -e s/$/\"/`
# is this new category?
for index in `seq 0 $ncats`; do
cur_cat=${cat_vals[$index]}
if [ "$cur_cat" == "$cat" ]; then
new_cat=1;
fi
done
# if it is new category, add to arrays cat_vals and cat_clrs
if [ "$new_cat" -eq 0 ]; then
index=`expr $index + 1`;
cat_vals[$index]="$cat";
cat_clrs[$index]="$color";
ncats=`expr $ncats + 1`;
fi
new_cat=0;
done
# print the legend
for cat in `seq 1 $ncats`; do
echo "color ${cat_clrs[$cat]}" >>$TMP
echo "polygon" >>$TMP
echo "5 $line1" >>$TMP
echo "15 $line1" >>$TMP
echo "15 $line3" >>$TMP
echo "5 $line3" >>$TMP
echo "color black" >>$TMP
echo "move 16 $line2" >>$TMP
echo "text ${cat_vals[$cat]}" >>$TMP
line1=`expr $line1 - $step`;
line2=`expr $line2 - $step`;
line3=`expr $line3 - $step`;
done
d.graph input=$TMP
d.frame -s frame=left
cleanup
More information about the grass-dev
mailing list