Vector Analysis I

In this lesson, we’ll do an analysis to find the total area of each vegetation category within our burn perimeter and output the results as a comma separated table.

library(sf)
library(dplyr)

# Question:
# How much of each vegetation type is present within the fire perimeter? 

ard_path <- "data/AnalysisReady/AnalysisReady.gpkg"

fire <- st_read(ard_path, "fire_boundary")

veg <- st_read(ard_path, "vegetation")
unique(veg$CWHR_LIFEF)

# Create a new column called area that contains the area of each
# vegetation polygon in hectares
veg <- mutate(veg, area = st_area(veg))
veg$area <- units::set_units(veg$area, ha)

# Get the number of hectares of each vegetation type within the fire perimeter.
# Recall that the veg data was clipped to the perimeter of the fire in a previous lesson. 
veg_summary <- veg %>% 
  st_drop_geometry() %>% 
  group_by(CWHR_LIFEF) %>% 
  summarize(hectares = sum(area))
# Write the output table as a csv file
write.csv(veg_summary, "outputs/vegetation_area_in_fire_perimeter.csv", row.names = FALSE)