Continuous raster legend color tables from ps.map?

Malcolm Williamson malcolm at cast.uark.edu
Mon Feb 19 07:00:00 EST 1996


On Mon, 19 Feb 1996, Bill Hargrove wrote:

> Grassusers:
> 
> Is there a way with ps.map to do a raster color table legend for a
> continuous variable like elevation?  ps.map is great, but pages and
> pages of individual values with boxes are less than useful ...
> 
>                 Thanks,
>                         Bill H.
> 
Ok, I'm going to divulge one of our _secret_ techniques (with thanks to 
Rob Dzur of CAST). No, there is no way to create a continuously variable 
color bar directly in ps.map, but you can readily create a raster layer 
that can be patched into the raster layer you will use for your map. Here 
goes:

1. Let's say you're working with an (unlikely!) elevation map that has 
values from 1 to 100. You will need to generate a color bar with 100 shades.

2. Determine where you want to place the color bar on your map. The 
easiest way to do this is to use d.where, and find the coordinates of the 
upper-left and lower-right corners of your color bar. In other words, you 
can determine the width and length of the bar by picking the corners of 
it on your monitor. Let's say that we get the following numbers:

         Upper-left: 594700 4829100
        Lower-right: 595700 4829000

So, we will be making a color bar 100 meters high by 1000 meters long.

3. Construct the header for an ASCII raster file (see man page for 
r.in.ascii). The trick is in setting your rows and columns; we will 
create _rectangular_ cells (not square)! In this case, since we want the 
color to vary from left to right, we'll specify only _1_ row and 100 
columns (the number of categories that are in are original raster layer):

        north: 4829100
        south: 4829000
        east: 595700
        west: 594700
        rows: 1
        cols: 100

4. Next, you need to enter the values for the cells. Since there will 
only be one row of 100 cells, we simply need to enter one value for each 
cell, 1 through 100. These can be simply typed in, or you can write a 
brief shell script to increment and concatenate to the header. It doesn't 
matter how many values you write on one line; GRASS looks at the header 
info to determine the raster file structure.

        north: 4829100
        south: 4829000
        east: 595700
        west: 594700
        rows: 1
        cols: 100
  
        1 2 3 4 5 6 7 etc.

5. Run r.in.ascii to load this information into a GRASS raster file; 
let's call our example "colorbar".

6. Patch raster layer "colorbar" with the raster layer that it is based 
upon. Make sure that the "colorbar" layer is the second map in the input 
list: 
        r.in.ascii input=elevation,colorbar output=elevation_plus

The output map will apply the colortable from the first input map 
("elevation") to all of the raster cells, including those in the color bar.

7. In ps.map, use the "text" command to place any text that you want 
associated with the color bar.


That's it! It's pretty easy after you try it once.

Cheers,
        -Malcolm Williamson
--
Malcolm D. Williamson - GIS Specialist           E-mail: malcolm at cast.uark.edu
Center for Advanced Spatial Technologies      Telephone: (501) 575-6159
Ozark Rm. 12                                        Fax: (501) 575-5218 
University of Arkansas              
Fayetteville, AR 72701






More information about the grass-user mailing list