Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/poissonconsulting/fwatlasbc

A R package to get data from the Freshwater Atlas of British Columbia
https://github.com/poissonconsulting/fwatlasbc

bc fwapg fwapgr

Last synced: 17 days ago
JSON representation

A R package to get data from the Freshwater Atlas of British Columbia

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# fwatlasbc

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/poissonconsulting/fwatlasbc/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/fwatlasbc/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/fwatlasbc/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/fwatlasbc)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)

`fwatlasbc` is an R package for querying data from the [Freshwater Atlas](https://www2.gov.bc.ca/gov/content/data/geographic-data-services/topographic-data/freshwater) (FWA) of British Columbia.
Spatial data are returned as [simple features](https://github.com/r-spatial/sf).

`fwatlasbc` wraps [`fwapgr`](https://github.com/poissonconsulting/fwapgr) an R package that uses the [fwapg API](https://www.hillcrestgeo.ca/fwapg/index.html).

## Installation

You can install the latest version of `fwatlasbc` from [GitHub](https://github.com/poissonconsulting/fwatlasbc) with:

```r
# install.packages("devtools")
devtools::install_github("poissonconsulting/fwatlasbc")
```

## Demonstration

Find stream names using regular expression.
There may be more than one stream name that matches the regular expression.
```{r}
library(fwatlasbc)
streams <- fwa_find_stream_names("steep c")
streams
```

Add blue line keys (blk) to stream names.
There may be multiple streams with the same name.
```{r}
blks <- fwa_add_blks_to_stream_name(streams)
blks
blks <- blks[blks$blk == 356534225, ]
```

Alternatively get the nearest blue line key and river meter (rm) from the longitude and latitude.
The river meter is the distance in meters as the fish swims from the mouth of the river.
The distance_to_lon_lat is the how far the original point was from the stream in meters.

```{r}
fwa_add_blk_to_lon_lat(data.frame(lon = -132.26, lat = 53.36))
```

Get watershed (by aggregating fundamental watersheds) for a blue line key and river meter (by default 0).
If it errors try increasing the river meter.
```{r}
wshed <- fwa_add_watershed_to_blk(blks)
wshed
```

Get stream network for the watershed polygon.
Note that rm is from the original watershed while downstream/upstream_route_measure are the equivalents for the stream segment in the network.
```{r}
network <- fwa_add_collection_to_polygon(wshed, "stream_network")
network
```

Convert the stream network into a table of blue line keys with regularly spaced river meters starting at 0.
```{r}
# rms <- fwa_convert_stream_network_to_rms(network, interval = 100)
# rms
```

Plot the watershed, network and river meters.
```{r dpi=300, fig.width=7, fig.height=7}
ggplot2::ggplot() +
ggplot2::geom_sf(data = wshed) +
ggplot2::geom_sf(data = network, color = "blue") +
# ggplot2::geom_sf(data = rms) +
NULL
```

## Inspiration

`fwatlasbc` supersedes the archived [`fwabc`](https://github.com/poissonconsulting/fwabc) which retrieved data via [WFS](https://openmaps.gov.bc.ca/geo/pub/wfs?service=WFS&version=2.0.0&request=GetFeature&typeName=WHSE_BASEMAPPING.FWA_LAKES_POLY&outputFormat=json&SRSNAME=epsg%3A3005&CQL_FILTER=GNIS_NAME_1=%27Quamichan%20Lake%27) using [`bcdata`](https://github.com/bcgov/bcdata).

## Creditation

`fwatlasbc` relies on [fwapg API](https://www.hillcrestgeo.ca/fwapg/index.html) which is created, maintained and hosted by [Simon Norris](https://github.com/smnorris/fwapg) at [Hillcrest Geographics](https://hillcrestgeo.ca/main/).

## Contribution

Please report any [issues](https://github.com/poissonconsulting/fwatlasbc/issues).

[Pull requests](https://github.com/poissonconsulting/fwatlasbc/pulls) are always welcome.

### Code of Conduct

Please note that `fwatlasbc` is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.