Ps.map graph paper: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
Line 116: Line 116:
==== On Letter paper ====
==== On Letter paper ====


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


  11" - margins = 9"
  11" tall - margins = 9" grid canvas height
  8.5" - margins = 7.5"
  8.5" wide - 1/2" margins = 7.5" grid canvas width
 
So we (re)set the region to these numbers: (just 1/4" wider than the A4 one)
  g.region n=9 e=7.5
  g.region n=9 e=7.5
And save it for future reference:
  g.region save=letter
  g.region save=letter
  # 1/4" wider
 
And again we run ''ps.map'' with a similar set of commands:


<source lang="bash">
<source lang="bash">
Line 134: Line 140:
   end
   end
scale 1:1
scale 1:1
grid 1
  color black
  width 0.5
  end
vareas quarter_inch_grid
vareas quarter_inch_grid
   fcolor none
   fcolor none
   color grey
   color grey
  width 0.5
  end
grid 1
  color black
   width 0.5
   width 0.5
   end
   end
Line 155: Line 161:
</source>
</source>


Convert to PostScript:
And convert to PostScript:
  ps2pdf quarter_inch_letter.ps
  ps2pdf quarter_inch_letter.ps



Revision as of 09:56, 17 January 2010

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 first we'll use that to make copies of two grid sizes.

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

This will let us draw a 1" black grid over the top of a 1/4" grey grid for a nice effect.

If you were just displaying to the screen you could have done:

d.grid 0.25 -b -t color=220:220:220
d.grid 1


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. The map scale is 1:1, we use the vector grid we made with v.mkgrid to render the finer mesh, and the grid instruction to render the darker 1" overlay grid. Finally we'll place a 5" ruler at the bottom of the page with the scalebar instruction.

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

vareas quarter_inch_grid
  fcolor none
  color grey
  width 0.5
  end

grid 1
  color black
  width 0.5
  end

scalebar s
  where 4.134 10.75
# (4.134 is width a4 / 2, so the center of the page)
  length 5
  segment 20
  numbers 4
  end

end

EOF


You can convert PostScript to PDF with 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. This time the margin math is a bit simpler.

11" tall - margins = 9" grid canvas height

8.5" wide - 1/2" margins = 7.5" grid canvas width

So we (re)set the region to these numbers: (just 1/4" wider than the A4 one)

g.region n=9 e=7.5

And save it for future reference:

g.region save=letter

And again we run ps.map with a similar set of commands:

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
vareas quarter_inch_grid
  fcolor none
  color grey
  width 0.5
  end
grid 1
  color black
  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

And 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?)