# Basin Networks

## Setup

Load Packages and Import Files

    # 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.

    # 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
    #>  [1]  3587  3532 63937 63794 63938  3486  3432 40541  3435 40556  3427  3466
    #> [13]  3555  3594  3361  3344  3407  3558  3547  3396  3564  3581 63931  3607
    #> [25] 63804

## Plot Subbasin Routing

Generate an interactive map of subbasin routing.

    # import subbasin polygons
    map.subid <- st_read(file.path(model_path, "gis", "Nytorp_map.gpkg"))
    #> Reading layer `Nytorp_map' from data source
    #>   `C:\Users\a002416\AppData\Local\Temp\Rtmp84C8N6\Rinstd90c79cf1310\HYPEtools\demo_model\gis\Nytorp_map.gpkg'
    #>   using driver `GPKG'
    #> Simple feature collection with 25 features and 38 fields
    #> Geometry type: POLYGON
    #> Dimension:     XY
    #> Bounding box:  xmin: 518978 ymin: 6413496 xmax: 541065.4 ymax: 6444436
    #> Projected CRS: SWEREF99 TM

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