Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


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).

...

The examples are taken from the “Effects of Cyclone Yasi on Green Cover at Mission Beach” tutorial. It can be beneficial to put the code snippets in context by looking at a broader section of the R script. Code snippets have a  Boxes with grey background contain code snippets, and outputs have a white backgroundboxes with white background containt code (text) outputs.



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

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
#==================================================================================
# 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

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# 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


Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## 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)

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
SPGC.2011q3.rl = raster(paste(SPGC.path, 'SPGC_2011q3.vrt', sep="/"))
SPGC.2011q3.rl


Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## 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)

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# 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


Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## 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)

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
SPGC.2011q3.rlb = raster(paste(SPGC.path, 'SPGC_TS.vrt', sep="/"), band = (1 + (2011-1990)*4 + 2))
SPGC.2011q3.rlb


Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## class       : RasterLayer 
## band        : 87  (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)

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Load a Multiple-Bands Raster from a file containing a Multiple-Bands Raster
# ---------------------------------------------------------------------------
# Load the whole TS of rasters.
# We use the functions 'stack' or 'brick' depending on the desired raster object.
SPGC.TS.rb = brick(paste(SPGC.path, 'SPGC_TS.vrt', sep="/"))
SPGC.TS.rb


Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## class       : RasterBrick 
## dimensions  : 135159, 141481, 19122430479, 108  (nrow, ncol, ncell, nlayers)
## 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.1, SPGC_TS.2, SPGC_TS.3, SPGC_TS.4, SPGC_TS.5, SPGC_TS.6, SPGC_TS.7, SPGC_TS.8, SPGC_TS.9, SPGC_TS.10, SPGC_TS.11, SPGC_TS.12, SPGC_TS.13, SPGC_TS.14, SPGC_TS.15, ... 
## min values  :         0,         0,         0,         0,         0,         0,         0,         0,         0,          0,          0,          0,          0,          0,          0, ... 
## max values  :       255,       255,       255,       255,       255,       255,       255,       255,       255,        255,        255,        255,        255,        255,        255, ...

...