library(tidyverse)
library(spData)
library(spDataLarge)
library(sf)
library(stars)
library(terra)
Source Materials
The following materials are modified from Geocomputation with R by Robin Lovelace.
1. Get Started
- Create an
.Rproj
as your version controlled project for Week 4 - Create a Quarto document inside your
.Rproj
- Download this data folder from Google Drive and move it inside your
.Rproj
- Load all necessary packages and read spatial objects
<- terra::rast(system.file("raster/dem.tif", package = "spDataLarge"))
dem <- terra::rast(system.file("raster/landsat.tif", package = "spDataLarge"))
landsat <- terra::rast(system.file("raster/srtm.tif", package = "spDataLarge"))
srtm <- stars::read_stars(here::here("week4-discussion", "PER_elv.tif"))
peru <- rast(peru) peru
2. Your Task
Now, to meet this week’s learning objectives, your task:
- Plot a histogram and boxplot of
dem
- Reclassify
dem
and compute the mean for the three classes:
- Low, where elevation is less than 300
- Medium
- High, where elevation is greater than 500
- Calculate the Normalized Difference Vegetation Index (NDVI) and Normalized Difference Water Index (NDWI) of
landsat
and find a correlation between NDVI and NDWI
- Note: \(NDVI = (NIR - red)/(NIR + red)\)
- Note: \(NDWI = (green - NIR)/(green + NIR)\)
Apply the functions to the appropriate Landsat 8 bands. Landsat 8 bands 2-5 correspond to bands 1-4 for this raster. Bands are as follows:
Band | Color | |
---|---|---|
1 | blue | 30 meter |
2 | green | 30 meter |
3 | red | 30 meter |
4 | near-infrared | 30 meter |
- Find the distance across all cells in
peru
to its nearest coastline
- Hint: Use
terra::distance()
to find geographic distance for all cells - Note:
terra::distance()
will calculate distance for all cells that areNA
to the nearest cell that are notNA
- Weigh the distance raster with
peru
and visualize the difference between the raster created using the Euclidean distance (E7) and the raster weighted by elevation- Every 100 altitudinal meters should increase the distance to the coast by 10 km
- Change the resolution of
srtm
to 0.01 by 0.01 degrees
- Use all of the method available in the
terra
package - Note: The
srtm
raster has a resolution of 0.00083 x 0.00083 degrees