Cropping Rasters

It is often the case that the raster we are working with is not the exact size of the area from which our data are collected. It is a much easier situation if the raster is larger than the area than if you need to stitch together two raster Tiles to get all your data onto one extent. In my doctoral thesis work, the area of the southern Ozark mountains that my sites were in was not only straddling a boundary between existing rasters, it was also at the boundary of two UTM zones! What a pain.

Spatial data often consists of very large datasets. One way to minimize the amount of computational resources you are going to use in R is to select only the spatial regions (extents) that you are working in and get rid of the remaining data. This is particularly important if you are going to be doing isolation modeling for genetic connectivity as the cost surface raster needs to be translated into a connectivity network. Data outside your area of interest are unnecessarily taking both resources and time away from your work.

To crop a raster, we need to identify the region we wish to keep as an extent object. An extent is a vector of length 4 defined as c(xmin, xmax, ymin, ymax)  describing the boundaries of are of interest.

Here is an extent for the arapat data set.


This is the exact boundaries of the data set. However, it is probably a good idea to not have your map cropped exactly to your boundaries but have your most extreme locations plotted within the map boundaries. So I’ll take an approximation (rounding up and down as necessary) to use.

This can now be used as the area from within the alt raster that we want to keep.

And if we plot it, we see that it is more properly scaled for the region we are interested in working on.

Screen Shot 2016-03-18 at 1.33.39 PM