Although I like to carry out GIS analyses using the command line interface (CLI), creating maps is something I still tend to do using the graphical interface (GUI). And most of the time that makes perfect sense to me, creating something visual (the map), using visual tools (GRASS GUI gis.m or QGIS).
But things change when e.g., you have to create many maps of the same area changing one variable only, or if you want to automate the creation of maps in a script. GRASS GIS offers a simple syntax to create maps using the CLI. I used this to create the map below, which shows the percentage cover of woody vegetation in eastern Africa (Ethiopia, Kenya, Tanzania, Uganda, Rwanda, Malawi and Zambia).
- VCF: the woody vegetation cover was derived from the MODIS Vegetation Continuous Fields from the Global Land Cover Facility.
- Lakes: vector maps of the major lakes of Africa, from the Global wetland database
- Afr_admin: vector layer with national boundaries, extracted from the GADM database of Global Administrative Areas.
First step to create the map is to set the region. This will determine the extend and resolution of the data layers included in the map. The region I am using sets the extend to include above-mentioned countries and the resolution at 0.008333 degrees.
I am create a vector layer based on the extend of the current region, which I will use to set the background color of my image (to color all sea areas blue).
v.in.region --overwrite output=bckgrnd cat=1
Next, I have to set a number of so-called environment variables, which will affect how the map is drawn. See the manual for d.mon for information what these variables do.
Next, I am using the following commands to create the map (follow the links for the manual pages):
- Start and stop the d.mon PNG driver driver.
- d.frame, which allows one to create two or more frames within an image
- d.vect to add vector layers
- d.rast to add raster layers
- d.font to set the font used for the text layers
- d.legend to add a legend
- d.grid to add a coordination grid
# Start the d.mon driver
# Create first frame for map
d.frame -c at=”12,100,0,100″
# Add data layers (I leave it up to you to find out why I am adding the Afr_adm two times)
d.vect map=bckgrnd type=area color=none fcolor=173:216:230
d.vect Afr_adm@Example type=area color=191:191:191 fcolor=229:229:229
d.rast -o map=VCFtrees@Example
d.vect map=Lakes@Example type=area color=none fcolor=173:216:230
d.vect Afr_adm@Example type=area where="NAME_ENGLI = 'Ethiopia' OR NAME_ENGLI = 'Kenya' OR NAME_ENGLI LIKE '%Tanzania%' or NAME_ENGLI = 'Uganda' OR NAME_ENGLI = 'Zambia'OR NAME_ENGLI = 'Malawi' OR NAME_ENGLI = 'Rwanda'" color=84:84:84 fcolor=none
# Add coordination grid. If you are using projected data layers, you can add a scale bar and north arrow instead)
d.grid -c size=1
# Add text with source of the VCF data layer
d.text text="Source VCF: http://www.landcover.org/data/vcf/" at=4,50 size=2 align=ll color="59:119:59" font=arial rotation=90
# Create second frame for legend
d.frame -c at="0,12,0,100"
#Set font and add legend and text with title
d.legend -v -s map=VCFtrees@Example at=30,50,5,50
d.text text="VCF: Percentage tree cover (%)" at=5,70 size=20 align=ll color="black" font=arial
#Stop the PNG driver, after which the layers are written to a png image.
This might seem more work then creating the map using the GUI. And to be honest, it was for me… the first time. However, the next 100 maps I had to make were a breeze as I just had to replace the name of one of the input layers (VCF layer) in each run
p.s. For anoth examples of the creation of maps in GRASS GIS, but using the ps.map module, see http://casoilresource.lawr.ucdavis.edu/drupal/node/944 or http://grass.osgeo.org/wiki/Ps.map_scripts