[GRASS-dev] d.vect.chart legends

Hamish hamish_nospam at yahoo.com
Sat Apr 21 08:01:22 EDT 2007


Hi,

I just added 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 (using default colors). 

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-dev mailing list