This is an old revision of the document!


Introduction to geostatistics with R

Guillaume Larocque, November 10 2014.

Books

Papers of interest

R packages

Educational software

EZ-Kriging Small Windows software that facilitates understanding of kriging equations.

Click here to download the zip file containing the scripts and the datasets that will be used during the workshop.

Please extract this zip archive to an easily accessible folder on your computer.

Digitize a polygon defining the boundary of your study site

You can digitize the boundary of your study site from a Google Satellite layer by following the following steps:

  1. Open QGIS.
  2. Activate the 'OpenLayers Plugin' in the list of Extensions
  3. Add a Google Satellite layer by using the OpenLayers extension (Web/OpenLayers Plugin).
  4. Note that the CRS of the canvas is now 'Google Mercator' (WGS 84 / Pseudo mercator).
  5. If you have other vector layer that can help you define the limits of your study area, you can add them to the canvas by clicking on the 'add vector layer' icon.
  6. Digitize the zone defining your study area. You first need to add a new polygon shapefile layer under Layer>New>New Shapefile layer. Specify the proper CRS depending on the extent of your study area and specify a name for your layer. It is always preferable to work with a reference system that uses meters as units, such as UTM (medium extent), MTM (small extent in Quebec) or Lambert (large extent). Refrain from using a latitude/longitude system.
  7. Activate Edit mote (Layer>Toggle editing) and digitize the polygon(s) by clicking on the icon and specify '1' as the ID.

Convert the polygon to raster format

  1. Find the Rasterize function under Raster>Conversion. Specify the polygon that you just created as the input layer, and choose a file name with a .tif extension as the output file. Choose 'Raster resolution in map units per pixel'. You then need to choose a resolution in the reference system's units used for the input polygon. For example, if you specified UTM as the CRS of the polygon, the resolution will be specified in meters. Choose a resolution that will yield a raster with a manageable size, with a maximum of a few hundred lines and columns (up to 2000-3000max). For example, if your study area is 2km by 3 km, you can specify 5 m. as the resolution, which will yield a raster of 400 pixels by 600 pixels.
  2. After you have clicked on OK, this raster will be saved on your computer as a .tif file. All pixels within the study area will have a value of 1, and pixels outside will have a value of 0.

Import the mask in R

  1. You can now import the mask in R:
mask<-readGDAL(file.choose())

and choose the raster .tif file.

Then, you can do

mask@data[mask@data==0]=NA

to change all the zero values to NA (nulls).

Your mask is now ready to use!