Welcome to TERN Knowledge Base
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:
- Load a Single Layer Raster from a Single Layer File.
- Load a Single Layer Raster from a Multiple Layer File.
- 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. 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 grey background, and outputs have a white background.
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 a Single Layer Raster from a Single Layer File
Example 1
Example 2
Load a Single Layer Raster from a Multiple Layer File
Example 1
Example 2
Load a Multiple Layer Raster from a Multiple Layer File
Provide your feedback about the experience with Knowledge base