Importing raster data with raster

For this chapter, you will need the following R Packages:

library(raster)

To import raster data, we need a package that can specifically handle raster datasets. The package raster has for a long time been the go-to package for this. However, this package is currently in the process of being replaced with a successor, terra. Since raster is still in heavy use, we will show you how you handle raster data with this package.

Single band raster

Download the sample dataset here and unzip it into your project folder. This dataset is a freely available sample for the swissALTI3D data. The full sample, including files at different resolutions, can be downloaded from here.

Now load the library raster the function raster to import the tif-file included in the zip file. Make sure you have set the path to your tif-file correctly.

library(raster)

swissAlti3D <- raster("sample_data/SWISSALTI3D_10_TIFF_CHLV95_LN02_2600_1196.tif")

The dataset is now imported into your project and ready to be viewed, analysed and processed. If we call the object in our console, we can see that the dataset was imported as a RasterLayer and can see some important statistics which you would typically find via Layer Properties -> Source in ArcGIS.

swissAlti3D

To visualize the dataset, we can simply call plot on our new object.

plot(swissAlti3D)

Multiband Raster

//todo explain how to import multiband raster



arc2r/book documentation built on March 5, 2021, 2:10 p.m.