4.5 Import raster data
We now import raster data as a .tif file file. Here we chose the data for Rouville in 2015 from the collection of tif files representing the canopy index computed by the Montreal Metropolitain Community (CMM) from an NDVI index and an elevation surface model, represents the low vegetation cover, the high vegetation cover of more than 3 meters (the canopy), the low mineral surfaces and the high mineral surfaces more than 3 meters (roof).
# Download tif file from web page in your working directory
if (!file.exists("data/550_CLASS_3m.tif")) {
# 87.9Mo
# https://observatoire.cmm.qc.ca/produits/donnees-georeferencees/#indice_canopee
download.file("https://observatoire.cmm.qc.ca/documents/geomatique/IndiceCanopee/2015/550_Canopee2015_3m.zip", destfile = "canopee.zip")
unzip("canopee.zip", files = "550_CLASS_3m.tif", exdir = "data")
unlink("canopee.zip")
}
# Read tif in R using raster
# The file named "660_CLASS_3m.tif" contains the canopy index for all the Montreal area, so we can read this file only
canopee_mtl <- raster("data/550_CLASS_3m.tif")
The canopy index raster has values from 1 to 5, has nrow(canopee_mtl)
pixels
by row and ncol(canopee_mtl)
pixels by column. Note that raster uses the
proj4string
representation of the coordinate reference system.
#R> class : RasterLayer
#R> dimensions : 19230, 8688, 167070240 (nrow, ncol, ncell)
#R> resolution : 1, 1 (x, y)
#R> extent : 322218, 330906, 5024710, 5043940 (xmin, xmax, ymin, ymax)
#R> crs : +proj=tmerc +lat_0=0 +lon_0=-73.5 +k=0.9999 +x_0=304800 +y_0=0 +datum=NAD83 +units=m +no_defs
#R> source : 550_CLASS_3m.tif
#R> names : X550_CLASS_3m
Similar to the sf package, raster also provides plot
methods for its own classes.