GMT (Generic Mapping Toolbox) in Docker

GMT (Generic Mapping Toolbox) is a very powerful tool for making maps. It is primarily a command line tool that creates Post Script files (yes, sound like very old times, but still powerful). It is available from the GMT website. GMT was created and is still maintained by Paul Wessel at the University of Hawai’i at Mānoa. My first GMT experience dates back to ~2010, when I was a Masters student.

Fun Fact: In mid 2010s I applied for Post Doc postion at the University of Hawai’i at Mānoa. I was very excited about the opportunity to work with Paul Wessel. Unfortunately, I didn’t get the position, but it was close!

I recently decided to try GMT again, and to save time on installation and configuration I decided to use Docker. I tried to find ready to use container with GMT, but finally decided to create my own. I’m sharing my Dockerfile and instructions on GitHub:

I’m going to use this container to create maps for my blog. I’m going to share the code and maps in the future posts. Stay tuned!

Quick usage instructions:

I will assume that you have Docker installed on your computer. If not, please follow the instructions on the Docker website.

Clone to repository and build the container:

docker build -t gmt:6.4.0 .

Create an alias (optional, recommended if you are using Linux or MacOS – have no idea how to do that on Windows):

alias gmt-docker='docker run --rm -v "$PWD/:/root/work/" -i -t gmt:6.4.0'

This will allow you to use the container anywhere on your computer – this is useful, because you need to map your current directory to the container to use it.

Now you can use the container. For example, to create a map of the USA you can use the following commands:

gmt-docker gmt set FONT_ANNOT_PRIMARY 5p,Helvetica
gmt-docker gmt psbasemap -R-128/-65/24/51 -Jl-96.5/40/23/52/1:40000000 -B10g2 -K -P >
gmt-docker gmt pscoast -R -Df -Ia/0.03p,black -J -N1/0.5p -N2/0.25p,- -G#dde6d5 -S#a5bfdd -A0/0/4 -W0.5p,black -O -P >>
gmt-docker convert -geometry 2048x2048 -density 600 -background white -flatten -trim +repage USA.png

This will create a map of the USA and save it as USA.png. The map will look like this:

Disclaimer: The purpose of this post is not to teach GMT or Docker. I’m just sharing my experience with these tools. If you want to learn more about GMT, please visit the GMT website. If you want to learn more about Docker, please visit the Docker website. I just hope I can make your journey with these tools a little bit easier.

I hope you will find this useful. If you have any questions, please let me know in the comments.

Leave replay