Science‎ > ‎

GRASS code


Importing and converting WorldClim data

Importing .bil data into GRASS using GDAL causes some trouble. Depending on the data format used things can be a little off. WorldClim data is 16-bit signed int data consequently grid values range from −32768 to 32767. GDAL assumes unsigned grid values and as such rescales all values over the range 0 to 65535.

To correct this issue you simply have to reclass all imported data to the original scale using r.mapcalc.

# convert values using simple rule
 r.mapcalc "$finalname = if(tmp>23767,tmp-65536,tmp)"

A full script, that can be used as a template, can be found in the download section or by clicking HERE. This script however imports and converts .bil files into xyz using GRASS and GDAL (correcting for the signing error in the mean time) but with minor adjustments it can be used to batch import data into GRASS.

(original details on how to convert data and general info on the WorldClim .bil format is clearly explained in this blog post by Paulo van Breugel)

Exporting data to Google Earth (kmz)

Not everyone has access to a GIS systems and it is sometimes useful to export data to maps. Google Earth provides additional functionality as the ability to overlay several maps and get a sense of geographic locations for less defined map data etc. However, Google Earth does not read geotiff or other GIS file formats directly (the pro version does however).

In order to make data accessible to people using the free Google Earth version I frequently use a script that I found online (credit goes to David Finlayson) and adjusted slightly to produce the .kmz container files as used by Google Earth.

The script can be found in the download section or by following this direct link.

Executing the bash script on the GRASS command line will present you with a GUI (the latest wxPython driven version of GRASS however doesn't play nice. The older tcl/tk interface will work just fine).

An example file can be downloaded. It shows the global mean minimum temperature (C) for Januari.

Latitude / Longitude maps

I always forget how to do this although it is so simple. Extracting latitude and longitude values from a map in a certain projection and putting them into a separate map. Here is the simple recipe:

g.region rast=yourrastermap

r.mapcalc "latitudes=y()"

r.mapcalc "longitudes=x()"

That's it!!