Load raster objects from files

Load raster objects from files

 

The function 'raster' from the 'raster' package provides methods to create a RasterLayer object. RasterLayer objects can be created from scratch, a file, an extent object, an image object, and other specific R objects (i.e. Raster*, Spatial*, im (spatstat); asc, kasc (adehabitat*), grf (geoR) or kde object).

 

To explore the contents and characteristics of a loaded raster we simply type its name.

 

 

 

EXAMPLES

 

Examples of how to load raster objects from files are presented below. Examples are provided for the three possible cases:

  1. Load a Single Layer Raster from a Single Layer File.

  2. Load a Single Layer Raster from a Multiple Layer File.

  3. Load a Multiple Layer Raster from a Multiple Layer File.

 

The examples are taken from the “Effects of Cyclone Yasi on Green Cover at Mission Beach” tutorial. Putint the code snippets in context, by looking at a broader section of the R script, could be benefitial. Boxes with grey background contain code snippets, and boxes with white background containt code (text) outputs.

 

 

We start by creating a path for the location where our raster file is stored

Since our files of interest are located in our current working directory we use the function ‘getwd’ to retrieve the absolute path of our current working directory of the R process. This step is not necessary. We could just (repeatedly) include the path to the data file in the ‘raster’ function call.

 

#==================================================================================# Load Data#==================================================================================# Provide the path where the files of interest are located#SPGC.path = "C:/Users/uqbblanc/Documents/TERN/04b-DSDP_GitHub/Prep/Landscapes_AusCover-RemoteSensing/Data_RS/Seasonal_PGC" SPGC.path = getwd() # Files are in the Current Working Directory

 

 

Load a Single Layer Raster from a Single Layer File

 

Example 1

 

# Load a Single Band Raster from a file containing a Single Band Raster# ---------------------------------------------------------------------# We can use the functions:'raster', 'stack' or 'brick' depending on the desired raster object. # Typically 'raster' is used for a single band raster object. SPGC.2010q3.rl = raster(paste(SPGC.path, 'SPGC_2010q3.vrt', sep="/")) SPGC.2010q3.rl

 

## class : RasterLayer ## dimensions : 135159, 141481, 19122430479 (nrow, ncol, ncell) ## resolution : 30, 30 (x, y) ## extent : -1944645, 2299785, -4910195, -855425 (xmin, xmax, ymin, ymax) ## coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs ## data source : C:/Users/uqbblanc/Documents/TERN/04b-DSDP_GitHub/Prep/Landscapes_AusCover-RemoteSensing/YasiEffectsonGCatMB/YasiEffectsonGCatMB_Tutorial/SPGC_2010q3.vrt ## names : SPGC_2010q3 ## values : 0, 255 (min, max)

 

Example 2

 

SPGC.2011q3.rl = raster(paste(SPGC.path, 'SPGC_2011q3.vrt', sep="/")) SPGC.2011q3.rl

 

## class : RasterLayer ## dimensions : 135159, 141481, 19122430479 (nrow, ncol, ncell) ## resolution : 30, 30 (x, y) ## extent : -1944645, 2299785, -4910195, -855425 (xmin, xmax, ymin, ymax) ## coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs ## data source : C:/Users/uqbblanc/Documents/TERN/04b-DSDP_GitHub/Prep/Landscapes_AusCover-RemoteSensing/YasiEffectsonGCatMB/YasiEffectsonGCatMB_Tutorial/SPGC_2011q3.vrt ## names : SPGC_2011q3 ## values : 0, 255 (min, max)

 

 

Load a Single Layer Raster from a Multiple Layer File

 

Example 1

 

# Load a Single Band Raster from a file containing a Multiple-Bands Raster# ------------------------------------------------------------------------# The Time Series (TS) starts on 1999q1 (in reality, it contains data from Dec 1989 to Feb 1990)# We want 2010q3 and 2011q3, which are 82((2010-1990)*4+2) and 86 (2011-1990)*4+2) bands away from the initial band SPGC.2010q3.rlb = raster(paste(SPGC.path, 'SPGC_TS.vrt', sep="/"), band = (1 + (2010-1990)*4 + 2)) SPGC.2010q3.rlb

 

## class : RasterLayer ## band : 83 (of 108 bands) ## dimensions : 135159, 141481, 19122430479 (nrow, ncol, ncell) ## resolution : 30, 30 (x, y) ## extent : -1944645, 2299785, -4910195, -855425 (xmin, xmax, ymin, ymax) ## coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs ## data source : C:/Users/uqbblanc/Documents/TERN/04b-DSDP_GitHub/Prep/Landscapes_AusCover-RemoteSensing/YasiEffectsonGCatMB/YasiEffectsonGCatMB_Tutorial/SPGC_TS.vrt ## names : SPGC_TS ## values : 0, 255 (min, max)

 

Example 2

 

SPGC.2011q3.rlb = raster(paste(SPGC.path, 'SPGC_TS.vrt', sep="/"), band = (1 + (2011-1990)*4 + 2)) SPGC.2011q3.rlb

 

 

 

Load a Multiple Layer Raster from a Multiple Layer File