library(tidyverse)
library(sf)
library(terra)
library(spData)
library(spDataLarge)
Source Materials
The following materials are modified from Geocomputation with R by Robin Lovelace.
1. Learning Objectives
- Use
terra
functionsaggregate()
andresample()
to create a new raster - Use
terra
functionsas.polygons()
to convert a raster to a vector of polygons
2. Get Started
- Create an
.Rproj
as your version controlled project for Week 5 - Create a Quarto document inside your
.Rproj
- Load all necessary packages and read spatial objects
# Load raster data representing grain sizes with the three classes clay, silt and sand
<- terra::rast(system.file("raster/grain.tif", package = "spData")) grain
3. Your Task
Now, to meet this week’s learning objectives, your task:
- Subset points higher than 3100 meters in
nz_height
(fromspData
) and create a template raster withrast()
, where the resolution is 3 km x 3 km for the extent of the subset dataset
- Count numbers of the highest points in each grid cell
- Find the maximum elevation in each grid cell
- With the previous raster, complete the following:
- Aggregate the raster that counts the highest points in New Zealand/Aotearoa
- Reduce its geographic resolution by half, such that cells are 6 x 6 km
- Plot the result
- Resample back to the original resolution of 3 km x 3 km
- Polygonize
grain
and filter to only keep squares that represent clay