Click the box titles below to expand:

How to's

XSLT

GOOGLE MAPS API

PHP

Perl

Document Object Model (DOM)

UNIX

Generic Mapping Tools (GMT)

Miscellaneous

Projects

Courses Taught

Latest Favorites

Mac OS X

Web Development

Beta

How To :: Generic Mapping Tools (GMT) Hints and Tips

If you are unaware of what GMT is then stop reading and visit the GMT homepage. In short GMT is what I always wanted when I was making maps as a graduate student. Although slightly esoteric (it is a map making tool after all, and cartography is a complex science, ask a cartographer or school teacher about Mercator projections!) it is probably the most useful coding I have ever learnt (excluding Vi and Vim of course!).

Bascially the most efficient way of coding in GMT is to write a series of GMT commands in a shell script. I use the tcsh shell, but bash and sh are just fine. Shell scripting is waaaaaayyyy beyond the scope of these tips, so please don't ask for help in writing shell scripts.

What follows are just some general tips (primarily to remind me!) in how to write efficient GMT scripts. I owe much of my initial GMT learning to my co-workers at UCSD, especially Jen Bowen and Debi Kilb. My acolyte period has been helped by Kris Walker and Kent Lindquist.

Define as many variables as you can

set TEMPDIR = .
set PS = $TEMPDIR/anza_jacinto.ps
set BASE = /opt/gmt/bin
set GRIDS = /hf/save/maps/world30_grids/Grids
set PS_GLOBE = $TEMPDIR/global.ps
set REGION = -117/33.2/-116.2/33.8r
set CENTER = -116.6/33.5/28

Psbasemap scale

These have been notoriously tricky for me to master. The manual page says:

-L[f][x]lon0/lat0[/slon]/slat/length[m|n|k][:label:just][+ppen][+ffill]
-L[f][x]///[m|n|k], append m, n, or k for miles, nautical miles, or km [Default]

So I typically code for a fancy scale...

$BASE/psbasemap -X0 -Y0 -P -R$REGION -JE$CENTER -V -Bg0.5a0.5:"":/g0.5a0.5:""::".":WeSN -K -Lf-116.8/33.5/34/20k >> $PS

Here f means a 'fancy' scale, -116.8 is the longitude of the center of the scale, 33.5 is the latitude of the center of the scale, 34 is the latitude at which the scale is calculated. This will differ if you locate it in different parts of the map, depending on the type of projection you use. I typically use an equidistant (-JE) projection, therefore this latitude is extremely important. The final integer is the length of the scale and in this example I defined 20 kilometers.

Clip regions

Clip regions are for places on the planet where you need to overlay, or mask, what is plotted underneath. I most commonly use it for recreating 'land-only' topography over an area that is below sea level (and therefore plots as a 'wet' area). These locations, although uncommon, are found in several areas around the world, such as the Salton Sea and the Caspian Sea. You need an xy file that defines the polygon that will be clipped. This can as simple as 4 points (a rectangle) or as complex as a multi-sided polygon.

# -- START: PLOT TOPO,BATHYMETRY CORRECTLY (including Salton Sea) --
# Salton Sea co-ords -R-116.8/-115/32/34
# Define a clip region
$BASE/psclip saltonsea.xy -P -R$REGION -JE$CENTER -V -K >> $PS
# Make the Salton Sea be 'land-only' and put into the clipping region
$BASE/grdimage saltonsea.grd -V -P -R$REGION -JE$CENTER -Clandonly.cpt -Isaltonsea.grad -O -K >> $PS
# Color the Salton Sea Blue
$BASE/pscoast -V -P -R$REGION -JE$CENTER -C201/244/255 -Df -O -K >> $PS
# Close psclip
$BASE/psclip -C -K -O >> $PS
# -- END: PLOT TOPO,BATHYMETRY CORRECTLY (including Salton Sea) --

GRD problems

Check a grd file is valid with grdinfo. You might need to add a '=' to correctly parse the grd file:

$BASE/grdimage anza_3.grd=2 -P -R$REGION -JE$CENTER -Clandonly.cpt -Ianza_3.grad -V -K -E100 -X2 -Y2 >> $PS

Further reading

Disclaimer

This information is freely provided as–is. Messing around with the command line and creating files is a serious business, and I accept no liability for errors created, systems corrupted, or hard–disk damage by you following these instructions. They worked for me but may not work for you. Remember to back–up EVERYTHING before you try any of this stuff — it is not simple OR easy!!!

If you have any questions about this please email me at rlnewman@ucsd.edu and I will try my best to help you out.

made with CSS     Valid XHTML 1.0!      Valid CSS!