[GRASS-user] d.vect.chart legends

Hamish hamish_nospam at yahoo.com
Sun Apr 22 08:02:52 EDT 2007


Hi,

I just added in 6.3-cvs a new -l flag to d.vect.chart to output info
needed to create legends for charts. Previously you just got different
colors with no reference to which columns they represented (if using
default colors). (the order was in the source code if you looked)

This can be parsed to make a legend, either using d.graph (like
d.vect.thematic does) or by storing the info in a raster map's metadata
and using d.legend to make the map--for example:


MAP=
COLUMNS=

#### setup temporary file
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
    echo "ERROR: unable to create temporary files" 1>&2
    exit 1
fi

d.vect.chart -l map="$MAP" type=point columns="$COLUMNS" > "$TMP"

NCATS=`tail -n1 "$TMP" | cut -f1 -d'|'`   # wc -l ?

# create small temporary map hold legend info
g.region save=previous_zoom
g.region n=1 s=0 e=1 w=0 res=1
r.mapcalc "tmp_chart_$$ = $NCATS"
g.region previous_zoom

#set cat labels
eval `g.gisenv`
awk -F'|' '{ printf("%d:%s\n", $1, $2) }' "$TMP" >> \
  "$GISDBASE/$LOCATION_NAME/$MAPSET/cats/tmp_chart_$$"

#set colors
r.colors tmp_chart_$$ color=rules --quiet << EOF
`awk -F'|' '{ printf("%d %s\n", $1, $3) }' "$TMP"`
EOF

#draw the legend
d.legend -c tmp_chart_$$ range=1,$NCATS at=50,90,5,10



enjoy,
Hamish




More information about the grass-user mailing list