Learning Objectives
Following this assignment students should be able to:
- Map polygon data based on properties
- Aggregating raster data inside of polygons
- Crop and mask spatial data
- Save spatial data
- Create vector data based on locations data in csv files
Reading
Lecture Notes
- Mapping polygon data based on properties
- Aggregating raster data inside polygons
- Why is ggplot plotting my UTM data as latitudes and longitudes and how do I make it stop
- Cropping and Masking Spatial Data
- Saving Spatial Data From R
- Creating vector data from csv
Place this code at the start of the assignment to load all the required packages.
library(stars)
library(sf)
library(ggplot2)
library(dplyr)
Exercises
Harvard Forest Soils Analysis (50 pts)
The National Ecological Observatory Network has invested in high-resolution airborne imaging of their field sites. Elevation models generated from LiDAR can be used to map the topography and vegetation structure at the sites.
Check to see if there is a
data
directory in your workspace withHARV
subdirectory in it. If not, Download the data and extract it into your working directory. TheHARV
directory contains spatial data for Harvard Forest including raster data for a digital terrain model (HARV_dtmFull.tif
) and a digital surface model (HARV_dsmFull.tif
), and polygon data for the site boundary (harv_boundary.shp
) and the soil types (harv_soils.shp
).- Make a map of the
harv_soils
data with the polygons colored based onDRAINAGE_C
column. Use the viridis color ramp. - Make a map of the
harv_soils
data with one facet (i.e., subplot) for each category in theDRAINAGE_C
column. - Using the
HARV_dtmFull.tif
data extract the maximum elevation (i.e., the DTM value) within each soils polygon. To get the maximum elevation instead of the mean value use themax
function instead ofmean
. Display a vector of the resulting elevations. - Add the vector of elevations from (3) to the original
sf
object and display the resulting data frame. - Make a map of the soil polygons colored based on their maximum elevation. Use the viridis color ramp.
- Make a map that is the same as (5), but preserves the UTM coordinates on the axes.
- Make a map of the
Cropping NEON Data (50 pts)
The National Ecological Observatory Network has invested in high-resolution airborne imaging of their field sites. Elevation models generated from LiDAR can be used to map the topography and vegetation structure at the sites.
Check to see if there is a
data
directory in your workspace with anSJER
subdirectory in it. If not, Download the data and extract it into your working directory. TheSJER
directory contains csv data on plot locations (sjer_plots.csv
), raster data for a digital terrain model (SJER_dtmFull.tif
) and a digital surface model (SJER_dsmFull.tif
), and vector data on the site boundary (sjer_boundary.shp
) for the San Joaquin Experimental Range.- Load the csv plots data (
sjer_plots.csv
) as ansf
object and display that object (don’t load the shape files, use the csv file). The data is in latitudes and longitudes, so the CRS code is 4326. - Reproject the plots data to the UTM coordinates of the DTM data (
SJER_dtmFull.tif
) and display the resulting object. - Crop the DTM data to the site boundary (
sjer_boundary.shp
). To do this, first reproject the site boundary to have the same CRS as the DTM. Make a map showing the site boundary and the cropped DTM data without null values. Use the viridis color ramp. - Use a bounding box to crop both the DTM data and the plots data. The bounding box should have
xmin = 256500
,xmax = 257500
,ymin = 4110000
, andymax = 4111000
. Make a map showing the cropped DTM (with no null values and the viridis color ramp) and the cropped points. Display the plot in the UTM coordinates. - Save the map from (4) as an image named
sjer_cropped_figure.png
. - Write the cropped DTM from (4) to a geotiff file. Name it
sjer_dtm_cropped.tif
. Write the cropped plots data from (4) to a shape file. Name itsjer_plots_cropped.shp
.
- Load the csv plots data (