HES 505 Fall 2023: Session 16
Use dplyr
with predicates
and measures
to subset and manipulate data
Use extract
to access raster data
Use zonal
to summarize access data
Join data into a single analyzable dataframe
How do Collaborative Forest Landscape Restoration projects compare to other National Forest lands with respect to social and wildfire risks?
Datasets - Forest Service Boundaries, CFLRP Boundaries, Wildfire Risk Raster, CEJST shapefile
Dependent Variable - CFLRP (T or F)
Independent Variables - Wildfire hazard, income, education, housing burdent
unzip
### FS Boundaries
tmp <- tempfile()
fs.url <- "https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.AdministrativeForest.zip"
download.file(fs.url, tmp)
tmp2 <- tempfile()
unzip(zipfile=tmp, exdir = tmp2 )
fs.bdry <- read_sf(tmp2)
### CFLRP Data
tmp <- tempfile()
cflrp.url <- "https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.CFLR_HPRP_ProjectBoundary.zip"
download.file(cflrp.url, tmp)
tmp2 <- tempfile()
unzip(zipfile=tmp, exdir = tmp2 )
cflrp.bdry <- read_sf(tmp2)
We know these are in different CRS
Project to the CRS of the raster
Using %>%
to pipe data through the function
We can use the []
notation to subset the one dataset based on the geometry of the other
Need USFS and CFLRP within the region
Then need tracts that overlap USFS
Use the codebook to identify the right columns
Then use select
from dplyr
geometries are sticky!
Simple feature collection with 6 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -1598729 ymin: 2388182 xmax: -1475201 ymax: 3000813
Projected CRS: unnamed
# A tibble: 6 × 5
GEOID10 LMI_PFS LHE HBF_PFS geometry
<chr> <dbl> <int> <dbl> <MULTIPOLYGON [m]>
1 16025970100 0.75 0 0.6 (((-1485848 2427049, -1485813 2426977, -148…
2 16057005500 0.43 0 0.44 (((-1567845 2843218, -1567803 2843209, -156…
3 16057005600 0.3 0 0.05 (((-1573408 2823058, -1573412 2823071, -157…
4 16009950100 0.55 1 0.4 (((-1566013 2857573, -1565966 2857623, -156…
5 16017950500 0.75 1 0.53 (((-1545064 2973813, -1545058 2973793, -154…
6 16017950400 0.6 1 0.68 (((-1544958 2973552, -1544957 2973564, -154…
Can use zonal
for one summary statistic
Or extract
for multiple
wildfire.zones <- terra::zonal(wildfire.haz, vect(cejst.df), fun="mean", na.rm=TRUE)
head(wildfire.zones)
WHP_ID
1 2997.7951
2 182.8864
3 386.9580
4 173.1703
5 193.4199
6 210.4406