This code downloads land cover data from the CDL in preparation for assessing the scope of coverage of pesticide use estimates by state and year.
Note that this code takes many hours to run!
library(cdlTools)
library(raster)
library(dplyr)
pest <- read.csv("../output_big/bee_tox_index_state_yr_cmpd.csv") %>%
na.omit()
states <- as.character(unique(pest$STATE_ALPHA))
# select even years when CDL is available for all states
yrs <- seq(2008, 2016, by=2)
#states <- c("OR", "AZ", "SD", "MS", "GA", "KY", "IN", "WI", "PA", "ME")
# download CDL
cdl <- getCDL(states, year = yrs)
# calculate value frequencies
freq_cdl <- lapply(cdl, 'freq')
# convert to dataframe
freq_cdl_df <- do.call(rbind.data.frame, freq_cdl)
freq_cdl_clean <- freq_cdl_df %>%
rownames_to_column(var = "state_yr") %>%
mutate(state = str_sub(state_yr, 1, 2),
yr = str_sub(state_yr, 3, 6)) %>%
dplyr::select(state, yr, value, count) %>%
remove_rownames()
write.csv(freq_cdl_clean, "../output_big/land-cover-summary.csv",
row.names=F)
This R Markdown site was created with workflowr