HARPgroup / HSPsquared

Hydrologic Simulation Program Python (HSPsquared)
GNU Affero General Public License v3.0
1 stars 0 forks source link

Local Channel trib network (nhd+ or custom project specific, small pump-store, etc) #16

Open rburghol opened 2 years ago

rburghol commented 2 years ago

Overview

Concepts

CBP Architecture Support

Data Acquisition

rburghol commented 1 year ago
# get outlet, known comid (point above beaver creek in Rivanna/Mechums)

 bct <- nhdplusTools::get_nhdplus(comid='8567219')

# this gets tonode/fromnode, but I am unfamiliar with the number scheme, what is it referring to? It;s not a comid...
bct$fromnode
# [1] 200061236
bct$tonode
# [1] 200061237
# How to get next down comid?
# get next up?

# this does not work
nhdplusTools::get_tocomid(bct)
# Error in `rename()`:
# ! Names must be unique.
# ✖ These names are duplicated:
#   * "id" at locations 1 and 2.
# Run `rlang::last_error()` to see where the error occurred.

# this also fails, though it avoids an error, since hte comid is the same as requesting feature, and tocomid is 0
nhdplusTools::get_tocomid(as.data.frame(list(tonode = bct$tonode, comid=bct$comid, fromnode = bct$fromnode)), remove_coastal = FALSE, return_dendritic = FALSE )
#     comid tocomid    tonode  fromnode
# 1 8567219       0 200061237 200061236
# 
bct$comid
#  8567219

# notr this
nhdplusTools::navigate_nldi(bct$geometry)
# or this:
nhdplusTools::navigate_nldi(bct)
# both yield:
# Error in check_nldi_feature(nldi_feature) : 
#   Missing some required input for NLDI. Expected length 2 character vector or list with optional names: featureSource, featureID
rburghol commented 1 year ago

Got this partially working due to help at nhdplusTools issue queue:

library(nhdplusTools)
#> USGS Support Package: https://owi.usgs.gov/R/packages.html#support
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1

start_point <- st_sf(
  id = 1, 
  geom = st_sfc(
    st_point(
      c(-78.652281, 38.071266)
    ), 
    crs = 4269
  )
)

sf_use_s2(FALSE)
#> Spherical geometry (s2) switched off

domain <- st_buffer(st_as_sfc(st_bbox(start_point)), .1)

# grab some sample data and plot the domain
nhd <- plot_nhdplus(bbox = st_bbox(domain))

# Also plot the start point.
plot(st_geometry(st_transform(start_point, 3857)), 
     add = TRUE, col = "red", cex = 2)

start_point <- st_join(start_point, nhd$network_wtbd)

wb_out <- get_wb_outlet(lake_id = start_point$COMID, 
                        network = nhd$flowline)

plot_nhdplus(outlets = list(wb_out$comid), streamorder = 2)
# fails with error:
# Error occured while plotting:  Error in UseMethod("st_transform"): no applicable method for 'st_transform' applied to an object # of class "NULL"

# Warning messages:
# 1: Unknown or uninitialised column: `origin`. 
# 2: In get_plot_data(outlets, bbox, streamord

image

rburghol commented 1 year ago

# get an nhd feature with known comid
mc = nhdplusTools::get_nhdplus(comid='8566905')
# Get centroid of NHD catchment
mc_cent = st_centroid(mc$geometry)
# get lat and lon
mc_lon = mc_cent[[1]][[1]]
# [1] -78.66296
mc_lat = mc_cent[[1]][[2]]