Skip to contents

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 = ', ')))
#> [1] "region parameters are: cat, ws"
print(paste0('A selection of available LakrCat metrics include: ',paste(name_params[1:10],collapse = ', ')))
#> [1] "A selection of available LakrCat metrics include: agkffact, al2o3, bfi, canaldens, cao, cbnf, clay, coalminedens, compstrgth, damdens"

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
#> [1] "Herbaceous Wetland Percentage 2016"
metric='pctdecid2019,fert'
fullname <- lc_fullname(metric)
fullname
#> [1] "Deciduous Forest Percentage 2019"                   
#> [2] "Synthetic Nitrogen Fertilizer Application Mean Rate"

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)
comid damdenscat damdensws pcturbmd2006cat pcturbmd2006ws
23756298 0.0000000 0.0000000 0.0293228 0.0293228
120054065 0.0000000 0.0007270 0.4348181 0.1451495
167120863 0.0243986 0.0243986 0.2086078 0.2086078
df <- lc_get_data(metric='pcturbmd2006,damdens', aoi='cat,ws', comid='23783629,23794487,23812618')
knitr::kable(df)
comid damdenscat damdensws pcturbmd2006cat pcturbmd2006ws
23783629 0.0192097 0.0008875 0.2091942 0.0213267
23794487 0.0000000 0.2433268 0.1958225 0.8832762
23812618 0.0320852 0.0071455 0.0115507 0.0032155

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)
comid pctbl2019ws pctconif2019ws pctcrop2019ws pctdecid2019ws pctgrs2019ws pcthay2019ws pcthbwet2019ws pctice2019ws pctmxfst2019ws pctow2019ws pctshrb2019ws pcturbhi2019ws pcturblo2019ws pcturbmd2019ws pcturbop2019ws pctwdwet2019ws
23783629 1.5601274 82.8417931 0.00000 0.0627022 3.3679487 0.0007988 0.0228444 0.2318785 0.1064740 1.500061 9.2003748 0.0027956 0.0838692 0.0232438 0.8217587 0.1733297
23794487 0.0000000 0.4014892 31.64465 1.8176509 0.1167968 42.3096576 11.9132783 0.0000000 3.0878166 1.744653 0.2043945 0.2627929 3.6718009 1.0146726 1.6351559 0.1751953
23812618 0.0006431 84.9302559 0.00000 0.0623806 0.9241336 0.0000000 0.5498498 0.0000000 0.0032155 4.111976 5.2984945 0.0000000 0.0533772 0.0032155 1.8714187 2.1910391