knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>", 
  warning = FALSE, 
  message = FALSE
)

Accessing and working with LakeCat

The StreamCatTools package was designed to simplify the use of StreamCat data in R, leveraging the new API for StreamCat. We now have functionality in the StreamCat API for accessing and working with LakeCat data and have added functions in StreamCatTools to access LakeCata data in R using the API.

We can actually pull data into R from LakeCat by simply passing a URL to extract from json. We have to hard-wire parameters and are limited in the number of records returned through a GET request.

res <- jsonlite::fromJSON("https://api.epa.gov/StreamCat/lakes/metrics?name=pcturbmd2006&areaOfInterest=cat&comid=22538788")
res$items

List LakeCat API parameters

List LakeCat parameters: Get a list of available LakeCat values for certain parameters using the lc_get_params function (right now just metric names and areas of interest for this function) via the API

library(StreamCatTools)
region_params <- lc_get_params(param='areaOfInterest')

name_params <- lc_get_params(param='name')

print(paste0('region parameters are: ', paste(region_params,collapse = ', ')))
print(paste0('A selection of available LakrCat metrics include: ',paste(name_params[1:10],collapse = ', ')))

Look up the display name or names for a metric using the lc_fullname function via the API

metric='pcthbwet2016'
fullname <- lc_fullname(metric)
fullname
metric='pctdecid2019,fert'
fullname <- lc_fullname(metric)
fullname

Get Waterbody COMIDs

In this example we use the lc_get_comid function to find COMIDs for a set of example lake locations we load into R.lc_get_comid is just a simple wrapper for get_waterbodies in the nhdplusTools R package. We can then use the COMIDs we derive for our lake locations to get LakeCat metrics for these lakes as we show in after this.

dd <- data.frame(x = c(-89.198,-114.125,-122.044),
                 y = c(45.502,47.877,43.730)) |> 
  sf::st_as_sf(coords = c('x', 'y'), crs = 4326)

comids <- lc_get_comid(dd)

Get data for COMIDs

In this example we access several variables, for several areas of interest, and for several COMIDs using the lc_get_data function. We'll show using both the COMIDS we derived with lc_get_comid function in previous chunk as well as with known COMIDS for NHDPlus waterbodies. Loads data into a tibble we can view.

df <- lc_get_data(metric='pcturbmd2006,damdens', aoi='cat,ws', comid=comids)
knitr::kable(df)
df <- lc_get_data(metric='pcturbmd2006,damdens', aoi='cat,ws', comid='23783629,23794487,23812618')
knitr::kable(df)

Get NLCD data

In this example we access National Land Cover Dataset (NLCD) data for 2019, just at the catchment level for several COMIDs using the lc_nlcd function. Loads data into a tibble we can view.

df <- lc_nlcd(comid='23783629,23794487,23812618', year='2019', aoi='ws')
knitr::kable(df)


USEPA/StreamCatTools documentation built on Feb. 23, 2025, 12:53 a.m.