Introduction Generic Mapping Tools

Posted on December 20, 2022  •  5 minutes  • 927 words  • Other languages:  Deutsch

The Generic Mapping Tools (GMT) is a collection of tools to create maps and other data visualizations. It shines when you want to create maps for printing (EPS, PDF), but you can also export maps to SVG and to more classical image formats like PNG or JPG. On this page, I will introduce GMT on Ubuntu.

Install GMT

GMT has been part of Debian and Ubuntu for many years. The software has changed a lot throughout the years, so older descriptions will deviate quite a bit from what I will show here. Version 6 of GMT is included in Ubuntu and can be used on the command line. In addition, there is PyGMT for Python, and GMT supports Julia (a language with an excellent reputation amongst programmers, but not widely used, unfortunately – makes me want to look at it). To install Generic Mapping Tools on a current Ubuntu (meaning the command line version), you have to install it via apt:

sudo apt install gmt gmt-gshhs-low gmt-gshhs-high gmt-gshhs-full

gmt-gshhs-full is only really needed if you want to create very detailed maps. A complete documentation of GMT with a lot of good tutorial can be found at https://www.generic-mapping-tools.org/ .

The First Example

GMT on the command line is best written in short scripts. Let’s start with a minimal example:

gmt begin europe_outline
gmt set GMT_THEME cookbook
gmt coast -R-11/20/32/60 -JM16c -B -Gblack
gmt end show

This will create a mercator projection of Europe. What do the settings do?

The output is quite nice:

Europa-Karte

You can change the settings a bit to create another output format and make the landmass look more colorful for example:

gmt begin europe_outline png
gmt set GMT_THEME cookbook
gmt coast -R-11/20/32/60 -JM16c -B -Gdarkgreen
gmt end show

Here, the output will be a PNG with a green landmass.

Make a Globe

Another nice example to show the capabilities of GMT:

LON=11.566667
LAT=48.133333
NAME='München'

gmt begin my_world
gmt set GMT_THEME cookbook
gmt coast -Rg -JG${LON}/${LAT}/16c -Bag -Dc -A5000 -Gwhite -SLightBlue
echo "${LON} ${LAT}" | gmt plot -Sc0.16c
echo "${LON} ${LAT} $NAME" | gmt text -Dj0.12/0.12 -F+f16p,Helvetica,DarkRed+jBL
gmt end show

First, we set three shell variables (you can change them, if you like). Then we start creating a PDF with the name my_world.pdf:

You can see the result here:

Der Himmel über München

As you can see, GMT contains a bit of a learning curve. But most of it is pretty straightforward and most of the commands work in a very similar way. So it is easy to start experimenting quite fast. The interesting thing about the command line version is the ease of adding data from other sources. You only need to convert them into simple text files usable in GMT.

You are welcome to test the scripts with other coordinates and projection definitions and check out the results quite quickly. GMT is capable of much, much more. Further information and tutorials on the command line options can be found at Dokumentationsseite von GMT .

By logging in into comments, two cookies will be set! More information in the imprint.
Follow me