Generic Mapping Tools: high quality map production
The creation of print quality maps can be a daunting task, especially when a scaleble output format (such as PDF) is required. Fortunately the Generic Mapping tools can be used to transform geographic data into conveniently packaged EPS or PDF files. Link to Perl-GMT example page. Excellent tutorial on grdimage.
Simple unix style commands are used to overlay subsequent layers of geographic information into either a Postscript or an EPS file. An example map consisting of California county boundaries, a hillshade of topography, and GPS points is presented below. the GMT commands required to prepare this map are listed below. Command names are in boldface type, input files are red, and output files are in green. A more detailed example on using data generated with GRASS in GMT can be found here: GRASS Users Group of Davis, CA.
PDF file here
Commands here
An example map created with GMT
GMT Commands:
- Setup some default parameters for GMT
gmtset COLOR_NAN 255/255/255 DOTS_PR_INCH 300 ANNOT_FONT_PRIMARY Times-Roman \
ANNOT_FONT_SIZE_PRIMARY 10 ANNOT_FONT_SIZE_SECONDARY 10 HEADER_FONT Times-Roman \
LABEL_FONT Times-Roman LABEL_FONT_SIZE 10 HEADER_FONT_SIZE 10 PAPER_MEDIA letter \
UNIX_TIME_POS 0i/-1i PS_COLOR CMYK Y_AXIS_TYPE ver_text PLOT_DEGREE_FORMAT DF
- Create a basemap, with lat/lon tics
psbasemap -JB-120/40/34/40.5/7i -R-122/-117.5/34/38.5 -Xc -Yc -B1 -K -P -V > ssc105s.ps
- Plot the landform raster data with a grayscale color table
makecpt -Cgray -T0/255/1 -V > grey.cpt
grdimage shade.grd=2 -Cgrey.cpt -J -R -K -O -V >> ssc105s.ps
- Create scale bars in miles and kilometers
psbasemap -J -R -Lf-121.5/34.5/34/50k:"Kilometers": -T-120.75/34.25/1.5c -O -K -P -V >>
style="color:green;">ssc105s.ps
psbasemap -J -R -Lf-121.5/34.25/34/50m:"Miles": -O -K -P -V >> ssc105s.ps
- Plot some vector data: Ca outline, Ca counties, and pit locations
psxy counties.xy -M -J -R -W1/100/100/100 -P -O -K -V >> ssc105s.ps
psxy ca.xy -M -J -R -W3/0/0/0 -P -O -K -V >> ssc105s.ps
psxy pit_locations.xy -J -R -Sc0.15c -W1/0/0/0 -G0/0/0 -P -O -K -V >> ssc105s.ps
- Label the pit locations
pstext pit_locations.labels -J -R -Dj0.1c/0.1c -G0/0/0 -P -O -K -V >> ssc105s.ps
- Make a small context map showing the entire state
psxy ca.xy -M -JB-120/40/34/40.5/1i -R-124.5/-114/32/42.5 -X0.25i -Y1.5i -W2/0/0/0 -P -O -K -V >> ssc105s.ps
psxy pit_locations.xy -J -R -Sc0.01c -W1/0/0/0 -G0/0/0 -P -O -K -V >> ssc105s.ps
psxy zoom_extent.xy -M -JB -R -W1/0/0/0 -P -O -V >> ssc105s.ps
Getting Background Raster Data from NASA (From a Lon/Lat Location in GRASS)
-
After setting up the region, get the global mosaic base (true color) map.
r.in.wms --o -o -p -c layers=global_mosaic_base style=visual \
mapserver=http://wms.jpl.nasa.gov/wms.cgi output=wms_global_mosaic \
format=png
-
Simple export to GMT compatible format. Since we are using integer data, and separate R/G/B rasters, the process is very simple:
r.out.bin -i -h in=wms_global_mosaic.green out=grd_green
r.out.bin -i -h in=wms_global_mosaic.red out=grd_red
r.out.bin -i -h in=wms_global_mosaic.blue out=grd_blue
-
Add to a GMT map with:
grdimage grd_red grd_blue grd_green ...
Detailed Magnetic Declination
Premise:
Setting the magnetic declination on a compass is a critical step in accurate measurement of bearings that can be translated to map or survey. As the location of the magnetic north pole is constantly moving, the magnetic declination reported on older topographic maps or compass housings are probably out of date. Current declination values for a single point, or for large regions can be found on the NOAA sites:
These resources are helpful, but a current, detailed (state-level) map of magnetic declination would be interesting.
Get the Data for California:
The NOAA website also has a service for generating magnetic declination estimates along a user-defined grid system. The result is a simple list containing longitude, latitude and declination values, one for each user-defined grid cell. This list of data can easily be imported into a GIS, converted to raster, and contoured at some level of detail. The result would then be a nice map of magnetic declination for the state of California-- representing the current magnetic properties of the Earth.
The grid of coordinates and declinations, along with a PDF map are attached at the bottom of this page.
UPDATE: it is also possible to get world-wide grids of various magnetic field properties from this site. This data can be directly read in as raster or vector points, and even plotted from GMT. Read in the GMT grid file into GRASS like this:
grd2xyz D_map_mf_2005/D_Grid_mf_2005.grd | r.in.xyz in=- out=mf_2005 fs='\t'
Stefan Maus has put together an excellent website on the Earth's magnetic field, containing much more detailed information than this simple demonstration.
Process in GRASS/GMT:
# LL location
g.region n=44:00:00N s=32:00:00N w=125:00:00W e=113:00:00W res=0.5
# read in as raster:
r.in.xyz in=temp/mag_dec/ca_1deg.xyz out=declin type=FCELL x=2, y=1, z=3
# read in the data as a vector:
v.in.ascii in=ca_1deg.xyz out=dec_points x=2 y=1 columns="x double, y double, declin double"
# note that the cells are not centered on the points
d.rast declin
d.vect dec_points icon=basic/point
d.grid size=2 fontsize=12
# save a GMT-style grid for plotting
# note syntax, and preservation of NULL cells
# set the region to something just a little smaller than CA
g.region n=42 s=32.5 w=-124.5 e=-115 res=0.5
r.out.bin in=declin out=- null=-9999 | xyz2grd -Gdeclin.grd -R-124.5/-115/32.5/42 -I0.5/0.5 -ZTLf -F -N-9999
CA Magnetic Declination Map
Make Map with GMT:
#setup the contouring
annotated_contour_interval=0.25 #deg
#setup the contour line colors
contour_color1="1/1/1"
# simple map of the unique locations
# define some global settings:
gmtset ANNOT_FONT_PRIMARY Times-Roman \
HEADER_FONT_SIZE 16 \
ANNOT_FONT_SIZE_PRIMARY 12 \
LABEL_FONT_SIZE 14 \
BASEMAP_TYPE plain \
PLOT_DEGREE_FORMAT DF \
PAPER_MEDIA letter+
#
# sample map centered on the western USA
pscoast -JB-119/38/36/40/6.5i \
-R-125/-113/32.5/42.5 -B4/2 \
-Gwhite -W0.5p \
-U"Magnetic Declination (E) as of March 2008 (http://www.ngdc.noaa.gov/seg/geomag/jsp/struts/calcGridIGRF). D.E. Beaudette." \
-A250 -Dh -Na -Xc -Yc -P -K > map.eps
# plot counties
psxy counties.xy -M -J -R -W1/200/200/200 -P -O -V -K >> map.eps
# countour the declination grid
grdcontour declin.grd -J -R -GN+1 -A${annotated_contour_interval}+k$contour_color1+s9 -Wa2/$contour_color1 -O -V >> map.eps
# crop map to a tight bounding-box, and convert to PDF
ps2raster map.eps -A -Tf
Generic GRASS-GMT Plotting System
Premise:
A generic press-quality plotting system for GRASS, based on GMT. Still a ways to go.
Notes:
- Export of raster data to GMT grid via GDAL is not well supported when the source raster contains nodata values.
- Exporting raster data with a combination of r.out.bin [...] | xyz2grd [...] is problematic when there are several rasters to export and they are of different resolutions, especially when changing the region resolution results in a non-integer cell size (xyz2grd fails).
- A more unified approach to this would drop sh hack altogether, and use the existing GRASS python bindings, along with the emerging GMT python bindings.
- Exporting thematic vector data is still problematic, however the new support for the GMT vector file format may improve the situation
- Exporting paletted raster data is complicated by the need for a CPT file, not sure if it is possible to convert the GRASS color rules file into one.
- Calculation of page layout measurements and rounding of numbers cannot be done with bash. See attached perl script.
Code Example:
see attached file