Extracting Data from Rasters

This document shows you how to extract data from rasters.

 

Getting The Libraries

First, I’ll load in some packages to get the ability to work with raster data and to load in the Arapatus attenuatus data set (it is part of the default gstudiopackage).

 

Loading and Cropping Rasters

We can load in the raster, and then crop it to just the are we need. These rasters were downloaded from [http://www.worldclim.org] and are much larger than the study area. This just makes it easier on the computer to not have to deal with such large areas. After cropping it, we will load in the annual precip and temperature data as well.

 

Getting Example Data from Araptus attenuatus

Now, lets grab the Araptus data and look at the data and plot out the locations.

 

 

png-3

Extracting Point Data

To elevation, temperature and precipitation from the rasters for each sampling location, we need to translate them into points first. I’ll first grab the coordinate data as a data.frame.

 

Then we can grab them using the normal functions in the sp library.

 

 

Plotting Trend lines.

Cool, lets sort this by latitude

 

and then plot out some values to look at what is going on.

png

 

png-1

 

png-2