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

Hamish hamish_b at yahoo.com
Wed Mar 3 21:21:42 EST 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. (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


> 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`
for TYPE in $SOIL_TYPES ; do
  i=`expr $i + 1`
  echo "UPDATE soils_wakeL SET DSL_NUM=$i WHERE DSL_NAME='$TYPE';"
) | 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.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 &

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

raster elevation_shade

vareas soils_wakeLc
   rgbcolumn GRASSRGB
   label  SOIL_CODE
   lpos 1

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

   where 1 8
   raster soils_wakeLc.legend
   font arial
   fontsize 12
   cols 1
   nodata Yes

hope it helps,


More information about the grass-user mailing list