GMT Part 2: A topographical map of South-Africa
I hope this does not come across as a tutorial of some sort, I am mostly writing things down for myself. But I know someone might one day copy and paste this as I’ve done numerous times, but this mostly for me to master GMT. In the previous GMT related post I created this basic map of South-Africa. The map does not however have any cities, provincial boundaries or topography.
A basic map of South-Africa created with GMT:
Note that I converted is from postscript format to reduce size.
So first we need to get some external topographic and administrative data for South-Africa. In this case I’ll use ETOPO data from the National Center for Environmental Informatics. The cool thing about the Etopo data is that it is already availible in the GMT readable grd format.
The data can be inspected with ncdump or another GMT tool, grdinfo,
Next we need the administrative data for South-Africa. GMT only has the national boundaries for world countries and then also the data for US states. The admin data can be freely obtained from the GADM Database. We need to get the shapefiles for SA in this case.
The shapefile data needs to be converted for use in GMT. This is done with a GDAL tool, ogr2ogr. GDAL is a amazing resource and in my mind the most powerful Geospatial tool out there. If you already have GDAL installed correctly, we can prepare the admin data. I only wanted the SA provinces so we do,
Which converts the shapefile into a GMT readable format. So now we have topography data and provincial data to create a more detailed map. I have removed the colors specified by the -R and -S switch for the basic. The topography color table will create colors for the map. Lets create a bash script to plot the map.
This is the map we should get,
Play around with the -T- option to get the desired colors. This map looks a little cooler then the first basic map, however, there is no names of cities or anything, lets change that. So in GMT you need a list with the latitude and longitude of cities to plot in the map, something like this:
The first and second column tells us the lat/lon of the city we want on the map while the other columns is related to text size, marker and of course the name of the city. In GMT we’re calling the psxy function to plot the points. Now all that’s required is to call the psxy and pstext to plot the location and names of the cities respectively.
And tada, a map with some cities in South-Africa