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 using the
read_csv
function from the readr
package. We
have to hard-wire parameters and are limited in the number of records
returned through a GET
request.
df <- readr::read_csv("https://java.epa.gov/StreamCAT/LakeCat/metrics?name=PctUrbMd2006&areaOfInterest=catchment&comid=22538788", show_col_types = FALSE)
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: catchment, other, riparian_catchment, riparian_watershed, watershed"
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='pcthbwet2011'
fullname <- lc_fullname(metric)
fullname
#> [1] "Herbaceous Wetland Percentage 2011"
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='catchment,watershed', comid=comids)
knitr::kable(df)
COMID | WSAREASQKM | CATAREASQKM | PCTURBMD2006CAT | PCTURBMD2006WS | DAMDENSCAT | DAMDENSWS |
---|---|---|---|---|---|---|
23756298 | 76.7322 | 76.7322 | 0.0293228 | 0.0293228 | 0.0000000 | 0.0000000 |
120054065 | 18081.5220 | 728.5806 | 0.4348181 | 0.1451495 | 0.0000000 | 0.0007270 |
167120863 | 40.9860 | 40.9860 | 0.2086078 | 0.2086078 | 0.0243986 | 0.0243986 |
df <- lc_get_data(metric='PctUrbMd2006,DamDens', aoi='catchment,watershed', comid='23783629,23794487,23812618')
knitr::kable(df)
COMID | WSAREASQKM | CATAREASQKM | PCTURBMD2006CAT | PCTURBMD2006WS | DAMDENSCAT | DAMDENSWS |
---|---|---|---|---|---|---|
23783629 | 1126.7541 | 52.0569 | 0.2091942 | 0.0213267 | 0.0192097 | 0.0008875 |
23794487 | 12.3291 | 1.3788 | 0.1958225 | 0.8832762 | 0.0000000 | 0.2433268 |
23812618 | 139.9473 | 31.1670 | 0.0115507 | 0.0032155 | 0.0320852 | 0.0071455 |
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.
COMID | WSAREASQKM | PCTURBOP2019WS | PCTSHRB2019WS | PCTOW2019WS | PCTCROP2019WS | PCTHAY2019WS | PCTBL2019WS | PCTWDWET2019WS | PCTURBLO2019WS | PCTDECID2019WS | PCTMXFST2019WS | PCTICE2019WS | PCTURBMD2019WS | PCTGRS2019WS | PCTHBWET2019WS | PCTURBHI2019WS | PCTCONIF2019WS |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
23783629 | 1126.7541 | 0.8217587 | 9.2003748 | 1.500061 | 0.00000 | 0.0007988 | 1.5601274 | 0.1733297 | 0.0838692 | 0.0627022 | 0.1064740 | 0.2318785 | 0.0232438 | 3.3679487 | 0.0228444 | 0.0027956 | 82.8417931 |
23794487 | 12.3291 | 1.6351559 | 0.2043945 | 1.744653 | 31.64465 | 42.3096576 | 0.0000000 | 0.1751953 | 3.6718009 | 1.8176509 | 3.0878166 | 0.0000000 | 1.0146726 | 0.1167968 | 11.9132783 | 0.2627929 | 0.4014892 |
23812618 | 139.9473 | 1.8714187 | 5.2984945 | 4.111976 | 0.00000 | 0.0000000 | 0.0006431 | 2.1910391 | 0.0533772 | 0.0623806 | 0.0032155 | 0.0000000 | 0.0032155 | 0.9241336 | 0.5498498 | 0.0000000 | 84.9302559 |