Skip to content

Instantly share code, notes, and snippets.

@ateucher
Last active March 11, 2020 00:16
Show Gist options
  • Save ateucher/e454e6a9061a5c68418856df73ec46e2 to your computer and use it in GitHub Desktop.
Save ateucher/e454e6a9061a5c68418856df73ec46e2 to your computer and use it in GitHub Desktop.
# install.packages(c("bcdata", "dplyr", "remotes"))
# remotes::install_github("bcgov/rems")
library(rems)
library(bcdata)
library(dplyr)
# Get the watershed boundary - I don't know if this is exactly the boundary you
# want but you could read in any spatial file you have instead using the sf package. Eg:
# columbia <- sf::read_sf("path-to-my-columbia-boundary.shp")
columbia <- bcdc_query_geodata("eaubc-freshwater-ecoregions") %>%
filter(FRESHWATER_ECOREGION == "Columbia Glaciated") %>%
collect()
# Get the EMS IDs of monitoring locations within that boundary of the specified types
# ('RIVER,STREAM OR CREEK', 'DITCH OR CULVERT', 'LAKE OR POND',
# 'SPRING OR HOT SPRING', 'SEEPAGE OR SEEPAGE POOL')
ems_locations <- bcdc_query_geodata("bc-environmental-monitoring-locations") %>%
filter(WITHIN(columbia),
LOCATION_TYPE_CD %in% c('13','21','27','05','23')) %>%
collect()
locations <- ems_locations$MONITORING_LOCATION_ID
# Use rems to get data for just those locations:
download_historic_data() # takes a long time the first time
historic_results <- read_historic_data(emsid = locations) %>%
filter(SAMPLE_STATE == "Fresh Water")
current_results <- get_ems_data() %>%
filter(EMS_ID %in% locations,
SAMPLE_STATE == "Fresh Water")
all_results <- bind_rows(historic_results, current_results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment