Welcome to Spatial Data in R! This first set of tutorials (in three parts) is designed to provide an introduction to the two types of spatial data you will encounter in R: vector data and raster data. By the end of this tutorial, you should have a good sense of how R thinks about spatial data, and how to import and export spatial datasets you may get from other programs or sources.
It’s best the everyone works with the same version of R to avoid problems, so please start by updating your installation of R to 3.2.3 (“Wooden Christmas-Tree”). Installers for R 3.2.3 can be found here.
Download the most recent version of RStudio here. RStudio has recently added some very nice features (like tab completion), so please update if you have an older version.
Next, we need to install some libraries. In this tutorial, we will work with three libraries:
sp
: for working with vector data,rgdal
: for importing and exporting vector data from other programs,raster
: for working with raster dataOn Windows:
Just run: install.packages(c("sp", "raster", "rgdal"))
On Mac:
Download GDAL complete
Doubleclick and install the .dmg
file as you are used to on a Mac
Make sure you have R Version 3.2.3 installed – if not update it.
Download the rgdal package from CRAN.
Place the downloaded rgdal_1.0-4.tgz
in your Desktop folder
Run install.packages("~/Desktop/rgdal1.0-4.tgz", repos=NULL)
Install raster
and sp
by running: install.packages(c("sp","raster"))
If everything went well, the following three commands should run without problem!
library (sp)
library (rgdal)
library (raster)
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.