[GRASS-user] ps.map legend with rgbcolumn colors

Hi there,

I haven't been able to find this in previous discussions but it seems like a trivial yet impossible (for me) to solve thing. (Running grass6.4-svn windows standalone installer win7.)

I am trying to get a ps.map using an input file like the following:

# ps.map input file
border y
    color black
    width 1
    end

raster shadedRelief

vareas ecologicalZones
    layer 1
    rgbcolumn RGB_COLOR
    label GEZ_CODE
    lpos 1
    end

vlegend
    where 0.5 6
    border black
    font arial
    fontsize 12
    cols 1
    end
end

I would like to print a categorical legend with the same colors as the rgbcolumn, but I only get one gray color that is different from the RGB_COLOR definitions:
https://docs.google.com/fileview?id=0B0EpsfMZ-IZYNzI2ZjRjMTQtNTNiNi00NTJkLWJlZjAtNzAyN2E0MTM3OWUw&hl=it

Any pointer?

Kind regards,

Luigi

On Wed, 3 Mar 2010, Luigi Ponti wrote:

I haven't been able to find this in previous discussions but it seems like a trivial yet impossible (for me) to solve thing.

Luigi,

   I think you missed my question on the same subject from late last week.

raster shadedRelief

I would like to print a categorical legend with the same colors as the
rgbcolumn, but I only get one gray color that is different from the

   You want a legend of the category colors for your shaded relief map?

   First, the shaded relief map is always in greys; from the Description
section in the man page, "The map is assigned a grey-scale color table."

   Second, if you want to drape a colored map on a 3D base use d.shademap
("d.shadedmap - Drapes a color raster over a shaded relief map using d.his".)

   Third, within ps.map use the colortable stanza to present a legend of
raster category colors.

Rich

Luigi Ponti wrote:

I haven't been able to find this in previous discussions
but it seems like a trivial yet impossible (for me) to solve
thing. (Running grass6.4-svn windows standalone installer
win7.)

(it needs to be explained better in the docs.)

I am trying to get a ps.map using an input file like the
following:

# ps.map input file
border y
   color black
   width 1
   end

raster shadedRelief

vareas ecologicalZones
   layer 1
   rgbcolumn RGB_COLOR
   label GEZ_CODE
   lpos 1
   end

vlegend
   where 0.5 6
   border black
   font arial
   fontsize 12
   cols 1
   end
end

I would like to print a categorical legend with the same
colors as the rgbcolumn, but I only get one gray color that
is different from the RGB_COLOR definitions:
https://docs.google.com/fileview?id=0B0EpsfMZ-IZYNzI2ZjRjMTQtNTNiNi00NTJkLWJlZjAtNzAyN2E0MTM3OWUw&hl=it

nice!

Any pointer?

the vector legend is by map, not by category. Because you only used the
vareas instruction once, you only get one entry in the vector legend.

two alternatives:

1) add one vareas instruction for every vector zone, and add a
    where column_name = 'zonename'
to each one. You might have to explicitly give the fill color, I don't
think it is smart enough to know that the SQL query only results in 1.
Set the label to be each zonename.
(easiest way for a few values)

2) take the 'v.colors -s' approach, and create a dummy raster map
containing a category file and color table matching what's in the
vector's DB. Then use the colortable command to display it. example:

(this exposes a bug in the ps.map categorical legend though! the fill
colors get rearranged!)

# North Carolina sample dataset

g.copy v=soils_wake,soils_wakeL

# assign soil type ID number to each soil of the 77 soil types
v.db.addcol soils_wakeL col='DSL_NUM integer'
SOIL_TYPES=`v.db.select soils_wake col=DSL_NAME | sort | uniq`
i=0
(
for TYPE in $SOIL_TYPES ; do
  i=`expr $i + 1`
  echo "UPDATE soils_wakeL SET DSL_NUM=$i WHERE DSL_NAME='$TYPE';"
done
) | db.execute

v.extract in=soils_wakeL out=soils_wakeLc type=area where="DSL_NUM > 70"
d.vect soils_wakeLc type=area -c where="DSL_NUM > 70"

v.colors -s map=soils_wakeLc column=DSL_NUM color=random

d.erase
d.vect soils_wakeLc type=area -a
g.rename vcolors_23877,soils_wakeLc.legend

#create cats file:
v.db.select -c soils_wakeLc columns=DSL_NUM,DSL_NAME fs=":" | \
  sort | uniq | r.category soils_wakeLc.legend rules=-

d.legend soils_wakeLc.legend

ps.map in=test.psm out=test.ps && gv test.ps &

#----test.psm
# ps.map input file
border y
   color black
   width 1
   end

raster elevation_shade

vareas soils_wakeLc
   rgbcolumn GRASSRGB
   label SOIL_CODE
   lpos 1
   end

#vlegend
# where 5.5 8
# border black
# font arial
# fontsize 12
# cols 1
# end

colortable
   where 1 8
   raster soils_wakeLc.legend
   font arial
   fontsize 12
   cols 1
   nodata Yes
   end
end
#----

hope it helps,
Hamish

Hamish:

(this exposes a bug in the ps.map categorical legend
though! the fill colors get rearranged!)

fixed in svn.

Hamish

Dear Hamish,

It definitely helped!

Luigi Ponti wrote:
  
I haven't been able to find this in previous discussions
but it seems like a trivial yet impossible (for me) to solve
thing. (Running grass6.4-svn windows standalone installer
win7.)
    

(it needs to be explained better in the docs.)
 
  
I am trying to get a ps.map using an input file like the
following:

[...]

I would like to print a categorical legend with the same
colors as the rgbcolumn, but I only get one gray color that
is different from the RGB_COLOR definitions:
[https://docs.google.com/fileview?id=0B0EpsfMZ-IZYNzI2ZjRjMTQtNTNiNi00NTJkLWJlZjAtNzAyN2E0MTM3OWUw&hl=it](https://docs.google.com/fileview?id=0B0EpsfMZ-IZYNzI2ZjRjMTQtNTNiNi00NTJkLWJlZjAtNzAyN2E0MTM3OWUw&hl=it)
    

nice!
  

It is global ecological zones from FAO http://www.fao.org/geonetwork/ with color scheme from http://colorbrewer2.org/ and underlying shaded relief from globe relief http://www.ngdc.noaa.gov/mgg/topo/globe.html (there is also 10m scale shoreline from http://www.naturalearthdata.com/).

I am impressed with ps.map results (never used before): it does look a lot more like a printed map.

  
Any pointer?
    

the vector legend is by map, not by category. Because you only used the
vareas instruction once, you only get one entry in the vector legend.

two alternatives:

1) add one vareas instruction for every vector zone, and add a
    where column_name = 'zonename'
  

On my system it needs to be unquoted (at least in my case, where values were integers) – I mean, no quotes at all.

to each one. You might have to explicitly give the fill color, I don't
think it is smart enough to know that the SQL query only results in 1.
  

Yes, it is not smart enough; I had to use fcolor option with R:G:B triplet in vareas in place of rgbcolumn.

Set the label to be each zonename.
(easiest way for a few values)
  

Thanks: I have gone this way, for now. See link below:
https://docs.google.com/fileview?id=0B0EpsfMZ-IZYYmYwYmRlMWItY2Y4NS00MTNhLWEzZWUtZjQ2Y2U0OTU2YzRi&hl=it

One thing I am not able to do yet, is to use system fonts (e.g. Arial). I have tried by setting absolute path but it doesn’t seem to work. I am afraid this is more of a postscript question… Is ps.map able to access and embed GRASS fonts? (ok, tried to get GRASS in.)

2) take the 'v.colors -s' approach, and create a dummy raster map
containing a category file and color table matching what's in the
vector's DB. Then use the colortable command to display it. example:
  

This is a great example that I need to study a bit more.

Thanks for your help,

Luigi

Luigi:

I am impressed with ps.map results (never used before): it
does look a lot more like a printed map.

that's the idea! :slight_smile:

> where column_name = 'zonename'

On my system it needs to be unquoted (at least in my case,
where values were integers) -- I mean, no quotes at all.

right, 'quotes' are for when you are matching strings

https://docs.google.com/fileview?id=0B0EpsfMZ-IZYYmYwYmRlMWItY2Y4NS00MTNhLWEzZWUtZjQ2Y2U0OTU2YzRi&hl=it

very good!

One thing I am not able to do yet, is to use system fonts (e.g. Arial).
I have tried by setting absolute path but it doesn't seem to work. I am
afraid this is more of a postscript question... Is ps.map able to
access and embed GRASS fonts? (ok, tried to get GRASS in.)

from the ps.map help page: (near the top)
"""
       font font name
              The name of the PostScript font. Fonts present in
              all PostScript implementations are: Times-Roman,
              Times-Italic, Times-Bold, Times-BoldItalic, Hel-
              vetica, Helvetica-Oblique, Helvetica-Bold, Hel-
              vetica-BoldOblique, Courier, Courier-Oblique,
              Courier-Bold, and Courier-BoldOblique.
              The default is Helvetica.
"""

PostScript needs to use a font known to PostScript printers, not TTF
fonts known to the system. Maybe there is a way around that but I don't
know it. Note the above list is the minimum set, there may well be more
available locally.

Hamish