lakefetch

Status at rOpenSci Software Peer Review R-CMD-check CRAN status Project Status: Active codecov

Calculate fetch (open water distance) and wave exposure metrics for freshwater lake sampling sites.

Motivation

Fetch is the unobstructed distance that wind can travel across open water. It is a key physical driver in lakes because it controls wave height, wave energy, and shoreline exposure. Fetch influences sediment resuspension, nutrient cycling, littoral habitat structure, and the distribution of aquatic organisms. Despite its importance, calculating fetch for inland lakes has required either manual GIS work or tools designed for coastal/marine environments that do not handle the irregular shorelines and small spatial scales typical of lakes.

lakefetch fills this gap by providing an end-to-end R workflow for freshwater fetch analysis: it downloads lake boundary polygons from OpenStreetMap, calculates directional fetch via a ray-casting algorithm, classifies sites by wave exposure, and optionally integrates weather data to estimate cumulative wave energy. It can also pull hydrological context (outlets, inlets, watershed area, connectivity) from the US National Hydrography Dataset (NHD) via the hydrogeofetch package. The package is designed for batch processing across many lakes and sites, making it practical for large-scale ecological and limnological studies.

Other R packages calculate fetch for related use cases. fetchR, waver, and windfetch target coastal/marine environments and require the user to supply coastline polygons; lakemorpho computes fetch as one of many morphometric parameters on a single user-supplied lake polygon. lakefetch is distinguished by its lake focus and automatic OpenStreetMap-based boundary download for batch workflows. See Similar Packages below for a detailed comparison.

Spatial Domain

lakefetch operates on two-dimensional geographic (curvilinear) coordinates. Input data are expected as latitude/longitude pairs (WGS84, EPSG:4326) or as sf objects in any CRS. Internally, all spatial calculations are performed in a projected Cartesian coordinate system (UTM zone automatically determined from site locations) to ensure accurate distance measurements in meters. The package uses the sf package for all spatial operations and is compliant with PROJ6+ and WKT2 coordinate reference system representations.

Installation

Install from CRAN:

install.packages("lakefetch")

Or install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("ropensci/lakefetch")

Quick Start

library(lakefetch)

# Load sampling sites from a CSV with latitude/longitude columns
sites <- load_sites(system.file("extdata", "sample_sites.csv", package = "lakefetch"))

# Download lake boundaries from OpenStreetMap
lake <- get_lake_boundary(sites)

# Calculate fetch for all sites
results <- fetch_calculate(sites, lake)

# View results - an sf object with fetch values and exposure categories
results$results

How It Works

  1. Load sites from a CSV or data frame containing latitude, longitude, and optional site names.
  2. Get lake boundaries automatically from OpenStreetMap, or load your own shapefiles/geopackages.
  3. Calculate fetch by casting rays from each site outward at regular angular intervals (default 5 degrees, configurable via lakefetch_options(angle_resolution_deg = 10)) and measuring the distance to the nearest shoreline in each direction.
  4. Classify exposure based on effective fetch: Sheltered (< 2.5 km), Moderate (2.5–5 km), or Exposed (> 5 km). Thresholds are configurable.

For each site, lakefetch returns:

Metric Description
fetch_0 … fetch_355 Distance to shore (m) at each compass bearing
fetch_mean Mean of all directional fetches
fetch_max Maximum directional fetch (longest open water distance)
fetch_effective Effective fetch (default: mean of 3 highest directional values)
exposure_class Categorical exposure classification

Three effective fetch methods are available: "top3" (default), "max", and "cosine" (the SPM/CERC cosine-weighted method from the Shore Protection Manual).

Features

Example Workflow

library(lakefetch)

# Built-in example data
data("adirondack_sites")

# Download lake boundaries from OpenStreetMap
lake <- get_lake_boundary(adirondack_sites)

# Calculate fetch with depth estimation
results <- fetch_calculate(sites = adirondack_sites, lake = lake)

# Visualize
plot_fetch_map(results)      # Map colored by exposure class
plot_fetch_bars(results)     # Bar chart of effective fetch
plot_fetch_rose(results, 1)  # Rose diagram for the first site

# Interactive Shiny app
fetch_app(results)

Key Functions

Function Description
load_sites() Load and validate sampling sites from CSV or data frame
get_lake_boundary() Download lake polygons from OSM or load from local file
fetch_calculate() Calculate directional fetch, effective fetch, and exposure class
add_lake_depth() Estimate lake depth from surface area (Cael et al. 2017)
add_lake_context() Add NHD hydrological context (US lakes; requires hydrogeofetch)
add_weather_context() Add historical weather and wave energy metrics (requires jsonlite)
plot_fetch_map() Map of sites colored by exposure category
plot_fetch_bars() Bar chart of effective fetch by site
plot_fetch_rose() Directional fetch rose diagram for a single site
fetch_app() Interactive Shiny app for exploring fetch results
fetch_app_upload() Standalone Shiny app with CSV upload (no coding required)

Using Local Boundary Files

If you have your own lake boundary as a shapefile or geopackage:

lake <- get_lake_boundary(sites, file = "my_lake_boundary.gpkg")
results <- fetch_calculate(sites, lake)

Known Limitations

Similar Packages

Several R packages calculate fetch or wave exposure, but they target different use cases:

Package Focus Key Differences
fetchR General fetch calculation Requires user-supplied coastline polygons; no automatic boundary download; single-polygon workflow; no batch multi-lake processing.
waver Wave energy for coastal sites Designed for marine/coastal environments; uses a different fetch algorithm (wedge-based); no lake-specific features like NHD integration or depth estimation.
windfetch Wind fetch for coastal environments Successor to fetchR; coastal focus; no OpenStreetMap integration or multi-lake batch processing.
lakemorpho Lake morphometry metrics Calculates fetch as one of many morphometric parameters (shoreline development, max length/width, volume); single-lake focus; requires user-supplied polygon; no wave energy, weather integration, or exposure classification.

lakefetch is distinguished by its focus on freshwater lakes, including: automatic lake boundary download from OpenStreetMap with spatial clustering for large datasets, batch processing of sites across multiple lakes, empirical depth estimation, NHD hydrological context for US lakes, and historical weather/wave energy integration. These features are designed for the common ecological workflow of analyzing field sampling sites across many lakes.

Example Datasets

The package includes three built-in datasets:

References

Citation

If you use lakefetch in your research, please cite:

Farrell J (2026). lakefetch: Calculate Fetch and Wave Exposure for Lake Sampling Points. R package version 0.1.3, https://github.com/ropensci/lakefetch.

Or in BibTeX format:

@Manual{,
  title = {lakefetch: Calculate Fetch and Wave Exposure for Lake Sampling Points},
  author = {Jeremy Lynch Farrell},
  year = {2026},
  note = {R package version 0.1.3},
  url = {https://github.com/ropensci/lakefetch},
}

To generate the citation from R:

citation("lakefetch")

AI Assistance Disclosure

This package was developed collaboratively with Claude (Anthropic). Claude contributed to all aspects of the codebase, including package architecture, function implementation, test writing, documentation, and CI/CD configuration. All code was reviewed and directed by the package author. Claude is credited as co-author on all commits via Co-Authored-By tags.

Contributing

Contributions are welcome. Please see CONTRIBUTING.md for guidelines on reporting bugs, suggesting features, and submitting pull requests.

Code of Conduct

Please note that the lakefetch project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

MIT License