[GRASSLIST:450] Re: creating legend file for vector map

Moritz Lennert mlennert at club.worldonline.be
Fri Jun 20 12:40:33 EDT 2003


Keith J. Forbes said:
> On Friday 20 June 2003 17:08, you wrote:
>> ML  Keith J. Forbes said:
>> ML  > Hi. I have imported using m.in.e00 e00 vector maps, and all the
>> associated ML  > categories have been imported and are stored in the
>> dig_cats directory. I ML  > would like to create a legend file
>> (preferably
>> have GRASS do this for me) ML  > so
>> ML  > that each category can de displayed with a different color and an
>> ML  > accompanying legend.
>> ML  >
>> ML  > The only info I have found so far is that I would have to create
>> this
>> bt ML  > hand
>> ML  > using the category files, which seems to be quite cumbersome.
>> ML  >
>> ML  > I hope there is another way to do this, and would appreciate any
>> help. ML  > Thanks
>> ML  > in advance for your indulgence of a GRASS newbie.
>> ML
>> ML  No, you will have to do it "by hand", but this could mean via a
>> script.
>> ML
>> ML  As an example:
>> ML
>> ML  Using a vector file with 11 categories, numbered 1-11 according to
>> the
>> ML  importance of a specific phenomenon (1 being the most important and
>> 11
>> the ML  least important), you could copy the dig_cats file corresponding
>> to
>> this ML  map into a working directory, there (within that copy) erase
>> all
>> the lines ML  before the first category, and use a script such as
>> ML
>> ML  awk 'BEGIN{FS=":"} {print $1, int($1*255/12), int($1*255/12),
>> ML  int($1*255/12)}' ReworkedDig_CatsFile > legend.file
>> ML
>> ML  to create a grey scale legend.
>> ML
>> ML  If you play around with the "int($1*255/12)" parts, you can create
>> ML  different color scales.
>> ML  However, if you do not want scales but a specific color for each
>> category, ML  then you will have to do this by hand...
>> ML
>> ML  Moritz
>> ML
>> ML
>
> Hi Moritz,
>
> Thanks for the script. I have been using Linux only a month longer than
> Grass, so please be patient when I ask how I would go about messing with
> the 255/12 parts to obtain a gradient of one color.

The legend file contains RGB values, i.e. red-green-blue, so for example

awk 'BEGIN{FS=":"} {print $1, int($1*255/12), "0",  "0"}'
ReworkedDig_CatsFile > legend.file

would give you a red scale since green and blue would be set to 0.

Similarly,

awk 'BEGIN{FS=":"} {print $1, "0", int($1*255/12),  "0"}'
ReworkedDig_CatsFile > legend.file

would give you a green scale, and

awk 'BEGIN{FS=":"} {print $1, "255" , int($1*255/12),  "0"}'
ReworkedDig_CatsFile > legend.file

would give you a red to yellow scale, and

awk 'BEGIN{FS=":"} {print $1, "255" , 255-int($1*255/12),  "0"}'
ReworkedDig_CatsFile > legend.file

a yellow to red scale.

Play around with the numbers to see what it gives you, or look at an rgb
color table and calculate the formulas you need.

Basically you should vary the 12 in 255/12 according to the number of
categories that you have, so it should be 255/n+1 or 255/n if you wish to
use the extremes of the color table (i.e. white and black if you use grey
scale).

Have fun !

Moritz




More information about the grass-user mailing list