Vous êtes sur la page 1sur 28

Generic Mapping Tools on Windows

A Beginners Guide

March 2014

Dharmamony Vijai and HaeKyun Yoo


School of Fisheries Sciences, Hokkaido University, Japan
Contents

List of figures iii

1. Introduction 1
1.1. Required software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2. Optional software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3. Installing Ghostscript and GSview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.4. Installing GMT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5. DOS Batch files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2. Your first map 4

3. Examples 7
3.1. India - script modified . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2. Korea - Japan coast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3. Japan Cities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4. Places I lived . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.5. North Arrow & Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.6. North Arrow & Scale Extended . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.7. Inset map with extent rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.8. Sampling stations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.9. Simple contour plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.10. Multiple Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Appendix 18

A. Quick reference 18
A.1. List of colours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
A.2. PostScript fonts used by GMT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
A.3. Chart of octal codes for characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
A.4. Predefined bit and hachure patterns in GMT . . . . . . . . . . . . . . . . . . . . . . . 25

ii
List of figures

Page 4 Page 7 Page 8 Page 9

Page 10 Page 11 Page 12

Page 13 Page 14 Page 15 Page 16

iii
CHAPTER 1

Introduction

What is GMT?
GMT is a set of programs that allows you to make plots and maps. These programs create Encapsulated
PostScript (eps) and Postscript (ps) output. On Windows you will need a viewer that supports such
(eps/ps) files. One such viewer is GSview, which allows eps and ps files to be viewed and printed.
A simple google search will take you to respective websites and you can download and install as any
other windows program (basic instructions are provided in the following sections).
GMT is developed and maintained by Paul Wessel and Walter H. F. Smith with help from a global
set of volunteers, and is supported by the National Science Foundation. It is released under the GNU
General Public License (http://gmt.soest.hawaii.edu/).

1.1. Required software


1. Ghostscript

2. GSview

3. GMT for Windows

1.2. Optional software


1. GIMP / Photoshop (importing the postscript (ps) file and modify)

2. Notepad++ (Text Editor with syntax highlighting)

3. Evince (a simple ps file viewer)

1.3. Installing Ghostscript and GSview


Download and install the latest version of ghostscript from http://www.ghostscript.com/

Download and install the latest version of GSview from http://pages.cs.wisc.edu/ghost/gsview/

1
1.4. Installing GMT
1. Go to website http://gmt.soest.hawaii.edu/projects/gmt/wiki/Download

2. Choose appropriate installer (Figure 1.1)

Figure 1.1. GMT download page

3. Install using the options as shown in the following screen shots (Figures 1.2 & 1.3).

Figure 1.2. Figure 1.3.

1.5. DOS Batch files


Come back and read this section after chapter 2. Microsoft Disk operating system (MS-DOS) is a non-
graphical command line operating system. Although the MS-DOS operating system is not commonly
used today, the command shell more commonly known as the Windows command line is still used. The
Windows command line (also MS-DOS window) is navigated using MS-DOS commands. In Windows
GMT runs in MS-DOS window, since GMT is actually a collection of commands without a graphical
user interface (GUI).
A batch file is a text file containing a series of commands that are processed in sequence. Batch
files are saved with a .bat file extension. Any simple text editor (Notepad, Notepad++, etc) can be
used to produce batch files. GMT scripts are saved as batch files with .bat extension. GMT scripts
usually have GMT commands as well as MS-DOS commands. Most of the MS-DOS commands are
not case sensitive (e.g. del = DEL; Table 1.1).

2
Double-clicking the batch file executes the commands and gives the result (map).

Table 1.1. Frequently used MS-DOS Symbols/Commands in GMT scripts


Symbol / Command Function
& Two commands on single line

^ Splitting long commands over multiple lines


echo Repeat the text typed in back to the screen
del Delete files from the computer
set Allows to change one variable to another
* wild card to represent one or more characters. e.g. "*.txt" would
mean all files with an extension of ".txt".
| This is used to pipe (direct) one commands output to another
command as an input for further processing.
> Direct output to a file
>> Output is appended to and not overwritten to an existing file
rem The line is not executed when the batch file runs. Used to add
remarks/memo.

3
CHAPTER 2

Your first map

Steps for your first map


1. Make a new folder.
2. Inside the new folder open notepad (Right clickNewText Document).
3. Type the following one line script into it.
 
pscoast -R60/100/5/40 -JM12 -Df -W1 -N1 -Ba10/a10WSne -Gskyblue -P > India.ps
 
4. Save As... India.bat (.bat extension is important).
Change Save as type to All Files (Default is .txt).
5. Now you got a batch file with an icon as shown here (Windows 7).
6. Double-click the batch file to execute the script.
7. You will get a postscript file with the name India.ps in the same folder. Safely ignore the extra
file (gmt.history) formed.
Right clickEdit, to modify the batch file (if needed).
8. Double-click the ps file to open with GSview (Provided ghostscript and GSview were installed
with default options). Click ok in the GSview nag screen to open the map (Figure 2.1).

Figure 2.1. India

4
Explanation

Map region (-R)

The -R switch specifies the extent of the map we want to generate. Longitude values corresponds to
the x range and latitude values corresponds to the y range.

Map projection (-J)

The projection is specified with the -J switch. In this example we used -JM12. This selects the
projection (Mercator) and sets the width of the map to 12 centimeters. UNIT of the width can be
cm, inch, or point. The default is centimeter, but this can be overridden on the command line by
appending c, i, or p to the width values (e.g. 12i).

Resolution (-D)

The -D switch selects the resolution of the data set used in creating the map. The available choices
are f, h, i, l, and c which correspond to full, high, intermediate, low, and crude. Here we used
the full resolution data set.

Shorelines (-W)

-W
The -W switch draw shorelines (Default is no shorelines).

5
National boundaries (-N)

This switch draw national boundaries in addition to the coastline.

Basemap (-B)

Set map frame and axes parameters. By default, all 4 map boundaries (or plot axes) are plotted
(named W, E, S, N). To customize, append the codes for those you want (e.g., WSn). Upper case
means plot and annotate while lower case just plots the specified axes.

Fill land colour (-G)

The fill colour used for the countries is specified using the -G switch. The colour can be specified by
colour name, by a decimal colour code (r/g/b, each in range 0-255), or by a hexadecimal colour code
(see appendix A.1 for a list of some available colours).

Portrait View (-P)

The -P switch sets the page orientation to portrait. Landscape is the default.

6
CHAPTER 3

Examples

The default behavior of all GMT commands can be adjusted with the gmtset command. This com-
mand is usually used prior to any commands which produce output

3.1. India - script modified

Figure 3.1. India - detailed script


Code for figure 3.1
set region=60/100/5/40
set prosca=M12
set reso=f
set bound=a10f5g5/a10f5g5WSne
gmtset PLOT_DEGREE_FORMAT dddF

pscoast -R%region% -J%prosca% -D%reso% -W2 -N1 -G150 -K -P > India.ps


psbasemap -R -J -B%bound% -O >> India.ps

del .gmtcommands4
del .gmtdefaults4

7
3.2. Korea - Japan coast

Figure 3.2. Korea Japan coast


 
Code for figure 3.2
 

set output=Kr_Jp_coast.ps
set range=120/150/20/50
set scale=m1:25000000
gmtset BASEMAP_TYPE = plain
pscoast -Dh -R%range% -W1 -G200 -J%scale% -Ba10df5dg5d -L145/22:15/35/500 -P > %output%
del .gmt*

8
3.3. Japan Cities

Figure 3.3. Japan Cities


set region=120/150/20/50 & set prosca=M12 & set reso=f
set plot=c0.3 & set bound=a10f5g5/a10f5g5WSne
gmtset PLOT_DEGREE_FORMAT dddF

pscoast -R%region% -J%prosca% -D%reso% -W2 -G150 -K -P > JapanCity.ps


psxy city.txt -R -J -S%plot% -G255/0/0 -W1 -K -O >> JapanCity.ps
pstext city.txt -R -J -G0/0/0 -D0.1/0.1 -K -O >> JapanCity.ps
psbasemap -R -J -B%bound% -O >> JapanCity.ps

del .gmtcommands4
del .gmtdefaults4

city.txt x = x location of the text string (Longitude)


141.35 43.07 12 0 0 LM Sapporo y = y location of the text string (Latitude)
140.73 41.77 12 0 0 LM Hakodate s = size of text in points
140.87 38.27 12 0 0 LM Sendai a = angle of text, in degrees (counter clock)
139.77 35.67 12 0 0 LM Tokyo f = font number
136.9 35.18 12 0 0 LM Nagoya j = justification (BL=bottom left, TR=top right,
136.65 36.57 12 0 0 LM Kanazawa CM=center middle, etc)
132.45 34.4 12 0 0 LM Hiroshima text string = text to be displayed
130.4 33.58 12 0 0 LM Hukuoka
127.7 26.22 12 0 0 LM Naha

x y s a f j text string

9
3.4. Places I lived

Figure 3.4. Places I lived


set region=65/150/5/50
set prosca=M12
set reso=f
set bound=a15/a10WSne
gmtset PLOT_DEGREE_FORMAT dddF FRAME_WIDTH 0.1c
pscoast -R%region% -J%prosca% -D%reso% -W2 -N1 -Gbisque2 -K -P > PlacesLived.ps
pstext title.txt -R -J -O -K -Wyellow >> PlacesLived.ps
psxy line.txt -R -J -W7/255/0/0 -O -K >> PlacesLived.ps
psxy circle.txt -R -J -Sc0.3 -Gblack -O -K >> PlacesLived.ps
pstext city.txt -R -J -D0.26c -Wlightgreen -O -K >> PlacesLived.ps
pstext country.txt -R -J -D0.26c -Gdarkblue -O -K >> PlacesLived.ps
psbasemap -R -J -B%bound% -O >> PlacesLived.ps
del .gmtcommands4
del .gmtdefaults4

line.txt
76.18 9.54
title.txt circle.txt
92.48 11.42
105 45 16 0 1 6 Places Lived 76.18 9.54
140.44 41.45
92.48 11.42
140.44 41.45
city.txt country.txt
76.18 9.54 10 0 1 3 Cochin 79 25.2 12 0 2 TR India
92.48 11.42 10 0 1 3 Andamans 146 33 12 0 2 TR Japan
140.44 41.45 10 0 1 3 Hakodate

10
3.5. North Arrow & Scale

Figure 3.5. Simple North Arrow and Scale bar


 
Code for figure 3.5
 

set region=60/100/5/40 & set prosca=M12


set bound=a10f5/a10f5WSne
set scale=x3.4i/0.4i/0/500 & set output=NorthArrow.ps
gmtset PLOT_DEGREE_FORMAT dddF

pscoast -R%region% -J%prosca% -Df -L%scale% -W2 -N1 -G150 -K -P > %output%
echo 63.5 12 24 0 14 BL N | pstext -R -J -G0 -O -K >> %output%
echo 66 8 36 90 34 BL \343 | pstext -R -J -G0 -O -K >> %output%
psbasemap -R -J -B%bound% -O >> %output%

del .gmt*

Font 34 used in the pstext is the ZapfDingbats font. Other possible north arrows are: \324, \331,
\344, \352, \362, \363, \370. For more options see table A.3 on page 24.

11
3.6. North Arrow & Scale Extended

Figure 3.6. North Arrow & Scale

set region=45/100/-25/38 & set prosca=M12


set bound=a10f5/a10f5WSne & set output=NorthArrowExtnd.ps
set scale01=x3.7i/3.7i/0/500 & set scale02=f88/9/8/1000k+lKilometers
set Narrow01=66/8/3c & set Narrow02=f60/-5/2c
set Narrow03=m85/-9/2i::+90/10/5
gmtset PLOT_DEGREE_FORMAT dddF LABEL_FONT_SIZE 12 HEADER_FONT_SIZE 30

pscoast -R%region% -J%prosca% -Df -T%Narrow01% -W0 -N1 -G150 -K -P


> %output%
pscoast -R -J -D -T%Narrow02% -W0 -N1 -G -K -O -P >> %output%
pscoast -R -J -D -T%Narrow03% -W0 -N1 -G -K -O -P >> %output%
pscoast -R -J -D -L%scale01% -W2 -N1 -G150 -K -O -P >> %output%
psbasemap -R -J -L%scale02% -B%bound% -O -V >> %output%

del .gmt*

12
3.7. Inset map with extent rectangle
Inset maps are used to provide either an overview of the area or a close up of a section or sections of
a map. Extent rectangles are a way to show the extent1 of one map within another map.

Figure 3.7. Inset map with extent rectangle

rem main map


set region=140.01/142.49/41.5/43 & set prosca=M21
set bound=a0.5/a0.5WSNE
set scale=f141.85/42.2/42/50k+lkm & set output=final.ps
gmtset PLOT_DEGREE_FORMAT ddd:mmF BASEMAP_TYPE plain
pscoast -R%region% -J%prosca% -Df -L%scale% -Wthin -G150 -K > %output%
rem dir = in degrees counter-clockwise from horizontal, for ellipse
echo 141 42.5 24 0 5 BL Noboribetsu | pstext -R -J -Gblue -O -K >> %output%
echo 141.25 42.35 35 1.6 0.8 | psxy -R -J -Se -Gp100/5:FgreenBred -W1 -O -K >> %output%
psbasemap -R -J -B%bound% -O -K >> %output%
rem Inset map
gmtset TICK_LENGTH 0
set region=136/149/40/47 & set prosca=M8
set bound=a5/a5wsne
pscoast -R%region% -J%prosca% -Df -W2 -N1 -G150 -X4.9i -Y0.2i -K -O >> %output%
rem Extent rectangle
echo 140 41.5 > tmp
echo 142.5 41.5 >> tmp
echo 142.5 43 >> tmp
echo 140 43 >> tmp
rem -L to close the polygon
psxy tmp -R -J -W10/red -L -O -K >> %output%
psbasemap -R -J -B%bound% -O >> %output%
del .gmt* & del tmp

1
boundary

13
3.8. Sampling stations

Figure 3.8. Sampling stations


 
Code for figure 3.8
 

set output=sampling_stations.ps
pscoast -R138/148/40/46 -Jm0.5i -B2 -P -W -Dh -K > %output%
psxy st01.txt -Sx0.15 -W2/255/0/0 -G0 -Jm -R -O -K >> %output%
psxy st02.txt -Sc0.15 -W1 -G0/0/255 -Jm -R -O -K >> %output%
psxy st03.txt -St0.2 -W1 -G0/255/0 -Jm -R -O >> %output%
del .gmt*

st01.txt st02.txt st03.txt


141 42.2 142 42.2 146 43.2
141 42.3 142 42.3 146 43.3
141 42.1 142 42.1 146 43.1
141.2 42.1 142 42 146 43
141.2 42.3 142.1 41.8 145.8 43.6
142.1 41.9 145.8 43.5
142.1 42.1 145.8 43.3
142.1 42

14
3.9. Simple contour plot

Figure 3.9. Simple contour plot


 
Code for figure 3.9
 

set file="D:\..\GMT\ETOPO1_Bed_g_gmt4.grd"
set output=contourAutumn.ps
gmtset PLOT_DEGREE_FORMAT F

grdsample %file% -R139.1/142.9/43.1/45.9 -F -Gnewarea.grd


grdmath newarea.grd -1 MUL = "grid2.grd"
grdcontour grid2.grd -Ccontour.txt -R -JM6i -Y3i -B1 -K -P > %output%
pstext stationName02.txt -R -JM -Gblue -K -O >> %output%
psxy stationAutumn.txt -R -J -Sc0.6 -Gred -W1p,red -K -O >> %output%
pscoast -Df -R -J -Wthin -Gdarkgray -K -O >> %output%
pstext MusashiBank.txt -R -JM -Gnavyblue -O >> %output%

del grid2.grd & del newarea.grd


del .gmtdefaults4 & del .gmtcommands4

contour.txt stationName02.txt stationAutumn.txt


50 A 141.2 44.8 18 0 0.5 CM AK10 140.0166667 44.65
100 A 139.7 44.63 18 0 0.5 CM AK02 141.1833333 44
150 A 140.9 43.95 18 0 0.5 CM AK06 140.85 44.78333333
200 A
250 A
300 A

MusashiBank.txt
140 44.85 18 0 3 CM Musashi Banks
141.9 43.94 18 0 3 CM Rumoi

15
3.10. Multiple Plot

Figure 3.10. Multiple plot

16
 
Code for figure 3.10
 

set output=Multipleplot.ps
set range=0/100/-10/10
set size=7/4
set bound2=a20f10/a4f2WSne

psbasemap -JX%size% -R%range% -B%bound2% -X4c -Y2.5 -K -P > %output%

set size=5/3

psbasemap -JX%size% -R%range% -B%bound2% -X9c -O -K >> %output%

set bound=a2.0f1.0g1.0:"X axis":/a2.0f1.0g1.0:"Y axis":WSne


set prosca=x0.5c -R-3/5/-3/5
gmtset LABEL_FONT_SIZE 0.5c HEADER_FONT_SIZE 0.5c LABEL_OFFSET 0.03c AN-
NOT_FONT_SIZE_PRIMARY 0.4c

psxy data.txt -J%prosca% -Sc0.25c -B%bound% -V -X-9c -Y7c -K -O >> %output%


psxy data.txt -J%prosca% -Sc0.25c -B%bound% -W1p/255/0/0 -G0/0/255 -V -X8c -O -K >> %out-
put%
psxy data.txt -J%prosca% -Sc0.25c -B%bound% -V -X-8c -Y7c -K -O >> %output%
psxy data.txt -J%prosca% -Sc0.25c -B%bound% -W1p/255/0/0 -G0/0/255 -V -X8c -O -K >> %out-
put%

set bound=a2.0f1.0g1.0:"X axis":/a2.0f1.0g1.0:"Y axis":WSne:."plot_test":

psxy data.txt -J%prosca% -Sc0.25c -B%bound% -V -X-8c -Y7c -K -O >> %output%


psxy data.txt -J%prosca% -Sc0.25c -B%bound% -W1p/255/0/0 -G0/0/255 -V -X8c -O >> %output%

del .gmtcommands4
del .gmtdefaults4

data.txt
0.0 2.70
3.17 0.43
-2.10 -0.10
2.89 3.94

17
APPENDIX A

Quick reference

A.1. List of colours


Following list contains some of the colours that can be used in GMT and their equivalent colour codes
(Hexadecimal, and RGB). Source: http://www.rapidtables.com/web/color/RGB_Color.htm

18
19
20
21
A.2. PostScript fonts used by GMT
GMT uses the standard 35 fonts that come with most PostScript laserwriters. If your printer does not
support some of these fonts, it will automatically substitute the default font (which is usually Courier).
The following is a list of the GMT fonts:

Table A.1. The standard 35 PostScript fonts recognized by GMT

When specifying fonts in GMT, you can either give the entire font name or just the font number
listed in this table. For the special fonts Symbol (12) and ZapfDingbats (34), see table A.3.

22
A.3. Chart of octal codes for characters

Table A.2. Octal codes and corresponding symbols for StandardEncoding (left) and ISO-
Latin1Encoding (right) fonts.

23
Table A.3. Octal codes and corresponding symbols for Symbol (left) and ZapfDingbats (right) fonts.

24
A.4. Predefined bit and hachure patterns in GMT
GMT provides 90 different bit and hachure patterns that can be selected with the -Gp or -GP option
in most plotting programs. The left side of each image was created using -Gp, the right side shows
the inverted version using -GP.

25

Vous aimerez peut-être aussi