---
title: "Basin Networks"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Basin Networks}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  fig.width = 7.1,
  fig.height = 6
)
```

## Setup
Load Packages and Import Files
```{r setup, message=FALSE}
# Load Packages
library(HYPEtools)
library(sf)

# Get Path to HYPEtools Model Example Files
model_path <- system.file("demo_model", package = "HYPEtools")

# Import HYPE Model Files
gd <- ReadGeoData(file.path(model_path, "GeoData.txt"))
gcl <- ReadGeoClass(file.path(model_path, "GeoClass.txt"))
```

## List All Contributing SUBIDs
Find all subbasins upstream of a specified SUBID.
```{r contributing}
# Select subid for which you want to find the upstream subids
Qobs.sbd <- 3587

# Get a list of all subids contributing to the outlet of the catchment
ups.sbd <- AllUpstreamSubids(subid = Qobs.sbd, gd = gd)
ups.sbd
```

## Plot Subbasin Routing
Generate an interactive map of subbasin routing.
```{r routing, message=FALSE}
# import subbasin polygons
map.subid <- st_read(file.path(model_path, "gis", "Nytorp_map.gpkg"))

# Generate map
# PlotSubbasinRouting(map = map.subid, map.subid.column = 25, gd = gd)
```
