7.4 raster objects

Let’s now download a simple raster of elevation using getData().

bel_elv <- getData(name = "alt", country = "BEL", path =  "data", level = 2)
#R>  Warning in getData(name = "alt", country = "BEL", path = "data", level = 2): getData will be removed in a future version of raster
#R>  . Please use the geodata package instead
plot(bel_elv)

7.4.1 Extract values

Note that extract() is in raster

val_south <- extract(bel_elv, bel_south)
val_north <- extract(bel_elv, bel_north)
#
par(mfrow = c(1,2))
hist(val_south[[1]])
hist(val_north[[1]])

7.4.2 Mask

elv_south <- rasterize(bel_south, bel_elv, mask = TRUE)
elv_north <- rasterize(bel_north, bel_elv, mask = TRUE)
par(mfrow = c(1,2))
plot(elv_south)
plot(elv_north)