/fwabc

An R package to read data from the BC Freshwater Atlas

Primary LanguageROtherNOASSERTION

Lifecycle: deprecated License: MIT

fwabc

***** This package is no longer being maintained - switched to fwapgr *****

fwabc is an R package to read data from the BC Freshwater Atlas.

fwabc uses the bcdata package to query the atlas remotely. No local storage of the database is required. fwabc provides convenience for common queries and tools/lookups to facilitate working with the atlas.

Function families

  • fwa_read_ - read features from BC Freshwater Atlas layers.
  • fwa_search_ - match a regular expression to named features.

Lookup tables

  • fwa_lookup_gnis
  • fwa_lookup_watershed_group
  • fwa_lookup_layer

These provide resources for finding layer names, features (GNIS_NAME, WATERSHED_GROUP_NAME, WATERSHED_GROUP_CODE) and which layers are available for given features.

There are 12 variants of fwa_read_ functions - one for each available layer. These functions are very similar, although arguments and acceptable input differ slightly due to differences in attributes.

# available layers
fwa_lookup_layer

As an example, let’s get the stream-network feature for Fraser River. The fwa_read_stream_network() accepts a vector of valid GNIS_NAME, WATERSHED_KEY, WATERSHED_GROUP_CODE, or WATERSHED_GROUP_NAME as input. Use the fwa_search_ functions if unsure about valid input.

fwa_search_gnis("fraser") 

fraser <- fwa_read_stream_network("Fraser River")
fraser

Now let’s get all named tributaries of the Fraser River with a stream order >= 5.

fraser_tribs <- fwa_read_stream_network("Fraser River", tributaries = TRUE, named_only = TRUE, min_stream_order = 5L)

The equivalent call using the bcdata package would be:

bcdata::bcdc_query_geodata("92344413-8035-4c08-b996-65a9b3f62fca") %>%
  bcdata::filter(CQL("FWA_WATERSHED_CODE LIKE '100-%'")) %>%
  bcdata::filter(!is.na(GNIS_NAME), STREAM_ORDER >= 5L) %>%
  bcdata::collect()

Finally, let’s create a map showing a number of layers in the ‘Skagit River’ watershed group.

group <- fwa_search_watershed_group("skagi|scagi")
group

# in this case, 'Skagit River' is both a GNIS_NAME and WATERSHED_GROUP_NAME,
# so we should specify the `input_type`.

stream <- fwa_read_stream_network(group, tributaries = TRUE, 
                                  min_stream_order = 5L, 
                                  input_type = "WATERSHED_GROUP_NAME")
lakes <- fwa_read_lakes(group, input_type = "WATERSHED_GROUP_NAME")
rivers <- fwa_read_rivers(group, input_type = "WATERSHED_GROUP_NAME")
wetlands <- fwa_read_wetlands(group, input_type = "WATERSHED_GROUP_NAME")
border <- fwa_read_watershed_groups(group, input_type = "WATERSHED_GROUP_NAME")

ggplot() +
  geom_sf(data = stream, size = 0.2) + 
  geom_sf(data = lakes, size = 0.3, fill = "steelblue") + 
  geom_sf(data = rivers, size = 0.3, fill = "blue") +
  geom_sf(data = wetlands, size = 0.3, fill = "green")
  geom_sf(data = border, size = 0.07) 

Installation

To install the latest development version from the Poisson drat repository

if(!"drat" %in% installed.packages()[,1]) 
  install.packages("drat")
drat::addRepo("poissonconsulting")
install.packages("fwabc")

To install the latest development version from GitHub

if(!"devtools" %in% installed.packages()[,1]) 
  install.packages("devtools")
devtools::install_github("bcgov/bcdata")
devtools::install_github("poissonconsulting/yesno")
devtools::install_github("poissonconsulting/err")
devtools::install_github("poissonconsulting/checkr")
devtools::install_github("poissonconsulting/fwabc")

Contribution

Please report any issues.

Pull requests are always welcome.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms