[GRASS-user] Vector map text legend

Hello!

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

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.

Any other ideas to do this?

Thanks

Martin Ytre-Eide

How about using Grass Plugin in QGIS to load your vectors and create
legend there? Not sure how it ties up with your python script.

Cheers
Saber

On Thu, 2011-03-31 at 11:39 +0200, Martin Album Ytre-Eide wrote:

Hello!

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

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.

Any other ideas to do this?

Thanks

Martin Ytre-Eide
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

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

Thank you for your suggestion. Unfortunately I don't know how to use qgis functions in python. I have had a look at it, and it seems tedious.

I ended up doing it with ps.map - it seemed I could use the .ps format anyway. I made a script which altered my ps.map file for each iteration - using the data.replace() function in python.

Martin

-----Opprinnelig melding-----
Fra: grass-user-bounces@lists.osgeo.org [mailto:grass-user-bounces@lists.osgeo.org] På vegne av Saber Razmjooei
Sendt: 1. april 2011 08:23
Til: Martin Album Ytre-Eide
Kopi: 'grass-user@lists.osgeo.org'
Emne: Re: [GRASS-user] Vector map text legend

How about using Grass Plugin in QGIS to load your vectors and create legend there? Not sure how it ties up with your python script.

Cheers
Saber

On Thu, 2011-03-31 at 11:39 +0200, Martin Album Ytre-Eide wrote:

Hello!

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

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.

Any other ideas to do this?

Thanks

Martin Ytre-Eide
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

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

This was exactly what I was looking for. This solves many of my legend issues. Thanks a lot.

A follow up question is: Would this be a good way to deal with logarithmic values in a legend?

-I convert rasters to have logarithmic values with r.mapcal: map = log(old_map,10)
-This gives me a nice map with a nice legend. One could use r.colors -g (logarithmic scaling), but this messes up the legend - the legend is still linear- and it does not look good.
-The problem is(my way of doing things) that the category numbers are log values as well(say 1-3-5 insted of 10-1000-100000), which there is noting wrong with, it is just not that easy to read.

So, is it a good idea to add category labels to all values (or a range of values) x - 10^x ( so for 1, I add 10 and so fort) or is it a better way to do this as well?

Martin

-----Opprinnelig melding-----
Fra: Hamish [mailto:hamish_b@yahoo.com]
Sendt: 2. april 2011 08:56
Til: grass-user@lists.osgeo.org
Kopi: Martin Album Ytre-Eide
Emne: Re: [GRASS-user] Vector map text legend

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

Hamish:

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

Martin Album Ytre-Eide wrote:

This was exactly what I was looking for. This solves many
of my legend issues. Thanks a lot.

glad to hear it.

A follow up question is: Would this be a good way to deal
with logarithmic values in a legend?

d.legend use=, but the version from GRASS 6.5 or 7, with Dylan's verbatim patch.

-I convert rasters to have logarithmic values with
r.mapcal: map = log(old_map,10)
-This gives me a nice map with a nice legend. One could use
r.colors -g (logarithmic scaling), but this messes up the
legend - the legend is still linear- and it does not look
good.
-The problem is(my way of doing things) that the category
numbers are log values as well(say 1-3-5 insted of
10-1000-100000), which there is noting wrong with, it is
just not that easy to read.

use= will draw at whatever levels you give it; I plan to backport
the (anti-)rounding patch for 6.4.2, ie after some time of live
testing. see https://trac.osgeo.org/grass/ticket/1147
feedback welcome.

So, is it a good idea to add category labels to all values
(or a range of values) x - 10^x ( so for 1, I add 10 and so
fort) or is it a better way to do this as well?

It's a matter of taste, but personally I am not a fan of band
rendering- where you (as a human) decide to arbitrarily assign
the category breaks can have a most remarkable(!) effect on how
the map is interpreted by other humans. See "how to lie with
statistics", "how to lie with maps", and other related books &
articles. You'll probably be most convinced by your own data one
day, when you pop one of your own insights after a new rendering.
In nature such thresholds are not so clearly defined. To aid the
viewer of a figure my favourite method is a continuous color
gradation + overlaid contour lines.

but anyway, ... the easiest way to display classes from raster
data in GRASS is to make a r.colors rule set like:

0% blue
25% blue
25% cyan
50% cyan
50% yellow
75% yellow
75% red
100% red

then r.category 'a - b' classes + d.legend use= can work.
hint for the above: remember that if you are careful the map
displayed and the legend displayed can actually be for two
different maps (one of which being a dummy which just exists
for making the legend).

(note to self- verify that GRASS 7 doesn't optimize that step
functionality away)

I think Arc & copycats use class breaks so much in their legends
simply as a matter of the vector-feature heritage of that
software; histogram classes make more sense if you start with
a number of sparse data points. In raster maps (traditionally
GRASS's strong point) it is more a case of continuous gradations.
shrug; just a small theory.

hope it helps,
Hamish

Martin Album Ytre-Eide <Martin.Album.Ytre-Eide <at> nrpa.no> writes:

Hello!

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.

[...]

Any other ideas to do this?

Just to complete the discussion on options: you can also check out the use of
d.graph in d.vect.thematic:

http://trac.osgeo.org/grass/browser/grass/trunk/scripts/d.vect.thematic/d.vect.thematic.py
(search for occurences of f_graph.write)

Moritz

Hello again.

I have followed your suggestion about r.catagory with rules like:
1:2:10-100
2:3:100-1000
etc

r.catagory map='name_map' vals=1,2

Confirms that these categories are present. However I have not been able to display these categories with d.legend with a number of combinations of flags and range, use etc.

What could I be missing?

Best regards,

Martin

-----Opprinnelig melding-----
Fra: Hamish [mailto:hamish_b@yahoo.com]
Sendt: 5. april 2011 09:30
Til: grass-user@lists.osgeo.org; Martin Album Ytre-Eide
Emne: Re: SV: [GRASS-user] Vector map text legend

Hamish:

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

Martin Album Ytre-Eide wrote:

This was exactly what I was looking for. This solves many of my legend
issues. Thanks a lot.

glad to hear it.

A follow up question is: Would this be a good way to deal with
logarithmic values in a legend?

d.legend use=, but the version from GRASS 6.5 or 7, with Dylan's verbatim patch.

-I convert rasters to have logarithmic values with
r.mapcal: map = log(old_map,10)
-This gives me a nice map with a nice legend. One could use r.colors
-g (logarithmic scaling), but this messes up the legend - the legend
is still linear- and it does not look good.
-The problem is(my way of doing things) that the category numbers are
log values as well(say 1-3-5 insted of 10-1000-100000), which there is
noting wrong with, it is just not that easy to read.

use= will draw at whatever levels you give it; I plan to backport the (anti-)rounding patch for 6.4.2, ie after some time of live testing. see https://trac.osgeo.org/grass/ticket/1147
feedback welcome.

So, is it a good idea to add category labels to all values (or a range
of values) x - 10^x ( so for 1, I add 10 and so
fort) or is it a better way to do this as well?

It's a matter of taste, but personally I am not a fan of band
rendering- where you (as a human) decide to arbitrarily assign the category breaks can have a most remarkable(!) effect on how the map is interpreted by other humans. See "how to lie with statistics", "how to lie with maps", and other related books & articles. You'll probably be most convinced by your own data one day, when you pop one of your own insights after a new rendering.
In nature such thresholds are not so clearly defined. To aid the viewer of a figure my favourite method is a continuous color gradation + overlaid contour lines.

but anyway, ... the easiest way to display classes from raster data in GRASS is to make a r.colors rule set like:

0% blue
25% blue
25% cyan
50% cyan
50% yellow
75% yellow
75% red
100% red

then r.category 'a - b' classes + d.legend use= can work.
hint for the above: remember that if you are careful the map displayed and the legend displayed can actually be for two different maps (one of which being a dummy which just exists for making the legend).

(note to self- verify that GRASS 7 doesn't optimize that step functionality away)

I think Arc & copycats use class breaks so much in their legends simply as a matter of the vector-feature heritage of that software; histogram classes make more sense if you start with a number of sparse data points. In raster maps (traditionally GRASS's strong point) it is more a case of continuous gradations.
shrug; just a small theory.

hope it helps,
Hamish

On 23/05/11 15:34, Martin Album Ytre-Eide wrote:

I think Arc& copycats use class breaks so much in their legends
simply as a matter of the vector-feature heritage of that software;
histogram classes make more sense if you start with a number of
sparse data points. In raster maps (traditionally GRASS's strong
point) it is more a case of continuous gradations. shrug; just a
small theory.

Classification of data into a limited number of categories is always about reduction of information for ease of interpretation. Yes, you can "lie with maps", but at the same time a series of treatments of information become much easier with a reduced set of categories (e.g. comparison of situation over time and space).

Definitely an interesting debate. But even the author of "How to Lie with Maps" does not put into question the use of categories in maps...

Moritz

In my case, I am looking for a way to get a logarithmic legend and thought that I might use categories for this.
You can set the r.colors -g to get logarithmic scaling of your map, but the legend will still be linear. - I can not get a logarithmic legend. I can do r.macalc log_map=log(map,10) and get a legend with values I would have to do 10^x to get the numerical value - so for now I use gimp to change the values 1,2,3 to 10,100,1000. -but I wish there was another way....

Martin

-----Opprinnelig melding-----
Fra: Moritz Lennert [mailto:mlennert@club.worldonline.be]
Sendt: 25. mai 2011 10:05
Til: Martin Album Ytre-Eide
Kopi: 'Hamish'; grass-user@lists.osgeo.org
Emne: Re: SV: SV: [GRASS-user] Vector map text legend (now more spesific about logarithmic raster legend)

On 23/05/11 15:34, Martin Album Ytre-Eide wrote:

I think Arc& copycats use class breaks so much in their legends
simply as a matter of the vector-feature heritage of that software;
histogram classes make more sense if you start with a number of sparse
data points. In raster maps (traditionally GRASS's strong
point) it is more a case of continuous gradations. shrug; just a small
theory.

Classification of data into a limited number of categories is always about reduction of information for ease of interpretation. Yes, you can "lie with maps", but at the same time a series of treatments of information become much easier with a reduced set of categories (e.g.
comparison of situation over time and space).

Definitely an interesting debate. But even the author of "How to Lie with Maps" does not put into question the use of categories in maps...

Moritz

Moritz wrote:

Martin Album Ytre-Eide wrote:
> I think Arc& copycats use class breaks so much in their
> legends simply as a matter of ...

(fwiw, those were my words, not Martin's)

Definitely an interesting debate. But even the author of
"How to Lie with Maps" does not put into question the use of
categories in maps...

Perhaps not, but I certainly do! The sensitivity in selection
of number of histogram breaks when your "n" is small or not
purely a normal distribution is hardly a fringe theory or novel
insight though, it's basic statistics.

I'm not saying don't use category breaks if you want to, just
that if you do, be aware of what you're doing and perhaps do some
sensitivity trials with breaks set at different places and see
if your interpretation is the same. It's only since I started
doing those that I've really been aware how important it is.

As earlier mentioned my current favorite method is to have
contour lines (ie category breaks) drawn over the top of a
continuous gradient background. Then you get the benefits of
both ways.

regards,
Hamish

Martin Album Ytre-Eide wrote:

In my case, I am looking for a way to
get a logarithmic legend and thought that I might use
categories for this.
You can set the r.colors -g to get logarithmic scaling of
your map, but the legend will still be linear. - I can not
get a logarithmic legend. I can do r.macalc
log_map=log(map,10) and get a legend with values I would
have to do 10^x to get the numerical value - so for now I
use gimp to change the values 1,2,3 to 10,100,1000. -but I
wish there was another way....

Dylan's patch to allow the d.legend use= option to work properly
with logarithmic values has now been backported to 6.4.svn.
Rebuild from the release branch source or grab a recent nightly
snapshot to try it.

for example:

d.legend mapname use=0.0001,0.001,0.01,0.1,1,10,100,1000

(before that worked, but the text labels got badly rounded)

Hamish

Thanks, this do work and I get an ok label, But I don't get a smooth gradient in this way. Is there a way?
I am also not getting any category labels.... I don't understand way they not show up at all?

Martin

-----Opprinnelig melding-----
Fra: Hamish [mailto:hamish_b@yahoo.com]
Sendt: 25. mai 2011 11:52
Til: Martin Album Ytre-Eide; Moritz Lennert
Kopi: grass-user@lists.osgeo.org
Emne: Re: SV: SV: [GRASS-user] Vector map text legend (now more spesific about logarithmic raster legend)

Moritz wrote:

Martin Album Ytre-Eide wrote:
> I think Arc& copycats use class breaks so much in their legends
> simply as a matter of ...

(fwiw, those were my words, not Martin's)

Definitely an interesting debate. But even the author of "How to Lie
with Maps" does not put into question the use of categories in maps...

Perhaps not, but I certainly do! The sensitivity in selection of number of histogram breaks when your "n" is small or not purely a normal distribution is hardly a fringe theory or novel insight though, it's basic statistics.

I'm not saying don't use category breaks if you want to, just that if you do, be aware of what you're doing and perhaps do some sensitivity trials with breaks set at different places and see if your interpretation is the same. It's only since I started doing those that I've really been aware how important it is.

As earlier mentioned my current favorite method is to have contour lines (ie category breaks) drawn over the top of a continuous gradient background. Then you get the benefits of both ways.

regards,
Hamish