library(here)
library(tidyverse)
library(sf)
library(tmap)
1. Learning Objectives
- Explore topological relationships with
sf
functions:st_intersects()
,st_intersection()
,st_within()
, etc. - Explore distance relationships with
sf
functions:st_distance()
,st_within_distance()
, andst_buffer()
- Learn about spatial and distance-based joins
- Practice writing error/warning messages and unit tests to diagnose outputs
2. Get Started
- Create an
.Rproj
as your version controlled project for Week 3 - 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
<- read_sf(here::here("data", "cpad_super_units_sb.shp")) %>%
sb_protected_areas st_transform("ESRI:102009")
<- read_sf(here::here("data", "sb_city_boundaries_2003.shp")) %>%
sb_city_boundaries st_transform("ESRI:102009")
<- read_sf(here::here("data", "sb_county_boundary_2020.shp")) %>%
sb_county_boundary st_transform("ESRI:102009")
<- read_sf(here::here("data", "aves_observations_2020_2024.shp")) %>%
aves st_transform("ESRI:102009")
3. Your Task
You will be wokring with the following datasets:
- Santa Barbara County’s City Boundaries (Santa Barbara County)
- California Protected Areas Database (CPAD)
- iNaturalist Research-grade Observations, 2020-2024 (via
rinat
)
Now, to meet this week’s learning objectives, your task:
- Find how many bird observations are within protected areas in Santa Barbara County
- Show the different outputs from a spatial subset and a spatial join
- Bonus Challenge: Try it out with a 5 km buffer around the protected areas too!
- Find the protected areas within 15 km of a city in Santa Barbara County
- Hint: Use
dplyr::filter()
to select a city fromsb_city_boundaries
- Explore the different outputs with
st_intersects()
,st_intersection()
, andst_within()
- Practice a distance-based join with
st_is_within_distance()
- Find the distance between your city of choice and a protected area of your choice
- Note:
st_distance()
finds the distance between the geometries’ edges