## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)

## ----install, eval = FALSE----------------------------------------------------
# install.packages("lakefetch")
# 
# # Optional packages for extra features:
# # install.packages("hydrogeofetch")                      # NHD integration
# # install.packages(c("shiny", "leaflet", "base64enc"))  # Interactive app

## ----load-sites---------------------------------------------------------------
# library(lakefetch)
# 
# # From the installed example CSV (two sites on Blue Mountain Lake, NY)
# sites <- load_sites(system.file("extdata", "sample_sites.csv",
#                                 package = "lakefetch"))

## ----get-lake, eval = FALSE---------------------------------------------------
# # Automatically download from OpenStreetMap (requires network)
# lake <- get_lake_boundary(sites)
# 
# # For very large or complex lakes, increase the Overpass timeout and
# # optionally simplify the polygon for faster downstream computation:
# lake <- get_lake_boundary(sites,
#                           timeout = 300,
#                           simplify_tolerance_m = 100)
# 
# # Or load a local shapefile / GeoPackage instead of querying OSM
# lake <- get_lake_boundary(sites, file = "path/to/lake_boundary.gpkg")

## ----calculate, eval = FALSE--------------------------------------------------
# results <- fetch_calculate(sites, lake)
# 
# # View results
# head(results$results)

## ----visualize, eval = FALSE--------------------------------------------------
# # Map of sites
# plot_fetch_map(results)
# 
# # Bar chart
# plot_fetch_bars(results)
# 
# # Interactive app (requires the shiny, leaflet, base64enc packages)
# fetch_app(results)

## ----options------------------------------------------------------------------
# # View current options
# lakefetch_options()
# 
# # Change options
# lakefetch_options(
#   buffer_distance_m = 20,      # GPS accuracy buffer
#   angle_resolution_deg = 10,   # Direction resolution (degrees)
#   max_fetch_m = 30000,         # Maximum fetch distance
#   use_parallel = TRUE          # Parallel processing for multiple lakes
# )
# 
# # Reset to defaults
# lakefetch_reset_options()

## ----nhd----------------------------------------------------------------------
# # NHD context is added automatically if available
# results <- fetch_calculate(sites, lake, add_context = TRUE)
# 
# # Check connectivity
# table(results$results$connectivity_class)

## ----multi-lake---------------------------------------------------------------
# # Sites are assigned to their containing lake polygon
# sites_with_lakes <- assign_sites_to_lakes(lake$sites, lake$all_lakes)
# 
# # Check assignment
# table(sites_with_lakes$lake_name)

## ----export-------------------------------------------------------------------
# # To CSV (without geometry)
# write.csv(sf::st_drop_geometry(results$results),
#           "fetch_results.csv", row.names = FALSE)
# 
# # To GeoPackage (with geometry)
# sf::st_write(results$results, "fetch_results.gpkg")
# 
# # Export ray geometries for GIS
# rays <- create_ray_geometries(results)
# sf::st_write(rays, "fetch_rays.gpkg")

