[GRASS-dev] d.vect.chart legends

Michael Barton michael.barton at asu.edu
Sun Apr 22 02:06:10 EDT 2007


Hamish,

This is conceptually a nice way for getting legends for a vector map, using
the tools we now have. There have been repeated requests for a way to get
legends for vector maps. Could this be systematized somehow in a script, or
better in the vector code, in some way.

For example, a flag that would automatically create a tiny legend raster
that could be used with d.legend. This could be built out of: the RGB column
for vectors, out of random vector colors, built with a script for
d.vect.thematic (until the C version is done), created for d.vect.chart like
you did for text output.

Michael


On 4/21/07 5:01 AM, "Hamish" <hamish_nospam at yahoo.com> wrote:

> 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
> 
> 

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton





More information about the grass-dev mailing list