[GRASS-user] Vector map text legend

Hamish hamish_b at yahoo.com
Sat Apr 2 02:56:18 EDT 2011


Martin Album Ytre-Eide wrote:
> I am looking for a way to make a legend to some vector area
> maps. The maps contain four different types of areas and are
> given different names.
> 
> I have made a python script running d.mon, d.vect etc. with
> the png driver producing about 14 png files, which then is
> used to create a gif file.
>
> A way to create a vector legend is to do v.to.rast and use
> the d.legend from the "dummy" rast -

(e.g. the v.colors script)

> however, I don't see how you can get a legend with text in this
> way? I don't think you can since raster should have numerical
> values. You could make a legend without category numbers and
> try to add the text with d.text, but I don't know if that's a
> good way of doing things.

d.text would work, but it's a lot of trouble to get it right.

the way to do this is to use r.category to add category labels
to each of your four raster category numbers, then use
d.legends's -c flag to hide the value of the number, so only the
label is displayed.

fwiw an approach to avoid the intermediary raster step is outlined
in wish #89.


> Then there is ps.map which solves this in a nice way - the
> problem is - I would like to keep the png format. I could
> just make the legend with ps.map - and add it to my png
> files with some image tools in python, but I am unsure of
> the result is worth the effort.

It is possible, actually I used this with html2latex's pstoimg
program quite recently to add a custom legend in a journal figure
created by other software, as it does such a nice job. Note there
are some customizations I need to finish/clean up which make
that a bit nicer to use (e.g. legend entries ordered by column
before row), and the ps.output addon has made an entirely new
vector legend tool.

pstoimg example:
  http://grass.osgeo.org/wiki/Ps.map_scripts#Converting_PostScript_to_PNG


good luck,
Hamish



More information about the grass-user mailing list