Ps.map graph paper

From GRASS-Wiki
Jump to navigation Jump to search

Creating graph paper with ps.map

The ps.map module is quite flexible. This example will demonstrate how to use it to create some graph paper and save it into a PostScript or PDF file ready for printing. With some slight tweaks you can make A3, Legal-sized, etc. paper with the grid resolution of your choosing.

This is not the most efficient method, but it's just a demonstration after all.

Background

Some useful numbers and facts to know before we start:

  • PostScript's (and thus PDF's) natural unit is the point. As in a "10 point" font size. A point is 1/72 of an inch, and so a 72 point font is 1" tall when printed. So for PostScript tasks it is both common and easiest to work directly with inches.
  • A sheet of A4 paper is 8.268" x 11.693". A sheet of Letter sized paper is 8.5" x 11".
  • 25.4 mm = 1"
  • The aspect ratio of metric paper sizes is length = width * sqrt(2).

Creating graph paper with a 1/4 inch grid

First create a new location using inches as the base unit.

Assuming you used the text-based interactive startup wizard:

  • Create a new location
  • [D] - Other projection
  • Projection: eqc (Plate Caree)
  • No datum
  • Ellipsoid: sphere
  • Radius of Earth: just use the default
  • Latitude, Longitude of center.. just set to 0.0
  • Enter plural form of units [meters]: inches
  • Enter conversion factor from inches to meters: 0.0254
  • set region:
Here we will want to calculate the size of the grid canvas. It will be a little smaller than the paper size. So given the above dimensions Letter-sized paper with 1/2" margins on the sizes and 1" on the top and the bottom, the grid canvas will be 7.5" x 9". So set north=9, south=0, west=0, and east=7.5. Set the resolution to 0.25. The exact default region is not important, it's just to get us started.


Next start up GRASS in a new mapset in this new location.


While the d.grid command can be used multiple times at different grid distances, unfortunately ps.map's grid instuction can only be used once. You can use v.mkgrid to make a grid pattern though, so we'll use that to make the finer scale grid.

v.mkgrid inch_grid grid=9,7 position=coor coor=0,0 box=1,1
g.region -p # check that res=0.25; read rows,cols for grid option
v.mkgrid quarter_inch_grid grid=36,30


On A4 paper

For A4 paper we'll use a 1/2" margin on the left and right, a 1" margin on the top, and a bit of a bigger margin on the bottom to leave room for a ruler.

So we are left with 8.268" - (2 * 0.5") = 7.268" wide and 11.693" - 1" - 1.5" = 9.193" tall. To maintain whole grid boxes we'll round this down to 7.25" x 9".

g.region  n=9 s=0 w=0 e=7.25 res=0.25

And save it as a named region for future reference.

g.region save=a4

With all that set up we can run ps.map:

ps.map out=quarter_inch_a4.ps << EOF

paper a4
  left 0.5
  right 0.5
  top 1.0
  bottom 1.5
  end
scale 1:1
grid 1
  color black
  width 0.5
  end
vareas quarter_inch_grid
  fcolor none
  color grey
  width 0.5
  end
scalebar s
  where 4.134 10.75
# 4.134 = width a4 / 2
  length 5
  segment 20
  numbers 4
  end
end

EOF


And convert to PostScript using the `ps2pdf` program that comes with Ghostscript:

ps2pdf quarter_inch_a4.ps

On Letter paper

This is mostly the same, we just modify the margins a bit and the region to match.

11" - margins = 9"
8.5" - margins = 7.5"
g.region n=9 e=7.5
g.region save=letter
 # 1/4" wider
ps.map out=quarter_inch_letter.ps << EOF

paper us-letter
  left 0.5
  right 0.5
  top 0.75
  bottom 1.25
  end
scale 1:1
grid 1
  color black
  width 0.5
  end
vareas quarter_inch_grid
  fcolor none
  color grey
  width 0.5
  end
scalebar s
  where 4.25 10.35
# 4.25 = width letter / 2
  length 5
  segment 20
  numbers 4
  end
end

EOF

Convert to PostScript:

ps2pdf quarter_inch_letter.ps


Creating graph paper with a 1 mm + 1 cm grid

On A4 paper

mm: create another location, but this time

Enter plural form of units [meters]: millimeters Enter conversion factor from millimeters to meters: 0.001

set region: (round down to nearest whole grid)

  1. n=9*25.4 e=7.25*25.4

n=230 e=190 res=1


v.mkgrid cm_grid grid=23,19 position=coor coor=0,0 box=10,10

g.region -p # read rows,cols

  1. that adds up to a lot, so we shrink it internally

v.mkgrid mm_grid_raw grid=230,190 v.build.polylines in=mm_grid_raw out=mm_grid g.remove vect=mm_grid_raw


  1. mm / A4

g.region n=230 e=180 s=0 w=0 res=1 g.region save=a4

  1. width grid: 180 mm / 2.54 = 7.087"
  2. ( width a4 - width grid ) / 2 = 0.59" margins
ps.map out=mm_a4.ps << EOF

paper a4
  left 0.59
  right 0.59
  top 1.0
  bottom 1.5
  end
scale 1:1
grid 10
  color black
  width 0.5
  end
vareas mm_grid
  fcolor none
  color 180:180:180
  width 0.5
  end
scalebar s
  where 4.134 10.75
# 4.134 = width a4 / 2
  length 100
  segment 10
  numbers 2
  end
end

EOF

convert to postscript

ps2pdf mm_a4.ps


On Letter paper

g.region n=230 e=190 s=0 w=0 res=1

  1. width grid: 190 mm / 2.54 = 7.48"
  2. ( width letter - width grid ) / 2 = 0.51" margins


ps.map out=mm_letter.ps << EOF

paper us-letter
  left 0.51
  right 0.51
  top 0.75
  bottom 1.25
  end
scale 1:1
grid 10
  color black
  width 0.5
  end
vareas mm_grid
  fcolor none
  color 180:180:180
  width 0.5
  end
scalebar s
  where 4.25 10.35
# 4.25 = width letter / 2
  length 100
  segment 10
  numbers 2
  end
end

EOF

convert to postscript

ps2pdf mm_letter.ps

See also

  • I'm pretty sure GMT has a graph paper demo, and I got the idea for this demo from them. (link?)