Purpose

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!

Libraries and functions

library(cdlTools)
library(raster)
library(dplyr)

Load state names from pesticide dataset

pest <- read.csv("../output_big/bee_tox_index_state_yr_cmpd.csv") %>%
  na.omit()

states <- as.character(unique(pest$STATE_ALPHA))

Load CDL data

# 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

# calculate value frequencies
freq_cdl <- lapply(cdl, 'freq')

# convert to dataframe
freq_cdl_df <- do.call(rbind.data.frame, freq_cdl)

Clean up dataframe

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()

Export data

write.csv(freq_cdl_clean, "../output_big/land-cover-summary.csv",
          row.names=F)

This R Markdown site was created with workflowr