Ps.map scripts

From GRASS-Wiki
Revision as of 12:16, 3 July 2008 by Neteler (talk | contribs) (Examples)
Jump to navigation Jump to search

Examples

Tips

Multiple raster images

While any number of vector maps can be drawn, ps.map will only let you draw one raster image or RGB image set per map.

  • If you want to show two or more overlapping raster maps you need to combine them with the r.patch module or r.mapcalc's '#' color operator.
(see also the r.his and r.composite modules)
  • If you want to show a number of raster maps side by side in a paneled figure you will have to do it in a two step process. The first step is to create each panel as an EPS file, the second step is to include these EPS files in the ps.map command file. Here is an example script demonstrating this.

Placing text below the map box

Use the text instruction with a y coordinate less than 0%. In the same way text can be placed above the map box by using a coordinate greater than 100%. To right justify the text set the x coordinate to 100% and the reference to right.

ps.map out=test.ps << EOF
 raster elevation.dem
 text 0% -6% Figure 1.1: Elevation map of Spearfish, SD
   fontsize 12
   ref left
   end
 end
EOF

Centering a map of fixed scale

By default ps.map centers the image at the top of the page and adjusts the map scale to suit. If you set a fixed map scale it will then place the map box at the top-left margins. Note that if the scale does not fit on the page it will be adjusted so it does, so keep an eye on it.

A method to recenter a map box with fixed scale follows. It involves the 'gv' program and a hand calculator. It is hoped in future this can be set automatically ... a pain, but you only have to do it once per map. Example uses the Spearfish dataset.

1. Run the ps.map process with no scale.
ps.map out=test.ps << EOF
 raster elevation.dem
 end
EOF

Scale set to 1 : 102867.
Reading raster map <elevation.dem in PERMANENT> ...
PostScript file [test.ps] successfully written.

If you view the resulting PS file you will see it nicely centered, i.e. extending to the left and right margins.

2. Change the scale shown by the program up to some nice round number and run ps.map again.
ps.map out=test.ps << EOF
 raster elevation.dem
 scale 1:125000
 end
EOF

Scale set to 1 : 125000.
Reading raster map <elevation.dem in PERMANENT> ...
PostScript file [test.ps] successfully written.

Note the scale is set to what we asked it to be, and the map box is now smaller and justified to the top-left margins.

3. Open the map in gv,
gv test.ps

and note a few numbers: the coordinate of the right edge of the paper (596 for A4), the right-hand border of the map box (466 for the above example), and the left edge of the map box (36 in the above example). tip: use the middle mouse button to draw a temporary zoom box in gv.

These numbers are measured in "points", which are 1/72". So the left edge of the map box is at 36pt, or 1/2", the given default left margin. In the same way a font of size 10 is 10/72" tall, and a 72pt font is exactly 1" tall on the printed page.

You can then calculate the map location to use to center the map box by finding the average of the current margins (in points):

( (page_right - box_right) + box_left ) / 2

And then converting points to inches:

avg_margin / 72.0

So for this example if 1.146" left and right margins are used the map should be centered. Use the maploc instruction to place the map.

ps.map out=test.ps << EOF
 raster elevation.dem
 scale 1:125000
 maploc 1.146 1.0
 end
EOF

Voilà!

PostScript files are simply plain text files!

To fix typos, insert special characters, etc., you can open the PostScript file in your favorite industrial-strength text editor, search for the text string, make the edit and resave. Much easier then regenerating the graph for something as simple as a spelling mistake or a figure number change.

Converting PostScript to PDF

ps2pdf is a GhostScript wrapper for converting PostScript files to PDF. The default is to create PDF with rasters sampled at 72dpi for viewing on a computer screen. To render at 1200dpi with defaults set for high quality printing, you can add some gs options to the operation:

ps2pdf -dPDFSETTINGS=/preprint -r1200 filename.ps


PDF files are simply containerized PostScript files!

Well, perhaps it is better to say they are an evolution. If you uncompress the PDF file you can edit it just as in the PostScript editing example above, and then recompress when you are done. A nice tool to compress/decompress PDF is pdftk. The pdftk program also lets you do nice things like concatenate a series of PDF pages into a single PDF document, and split a multi-page document into a series of single page PDFs. Very handy for splicing figures into a bigger document.