Joins geoconnex mainstem identifiers onto a table that contains NHDPlusV2 (comid/featureid) or NHDPlusHR (nhdplusid) identifiers using a lookup table.

add_mainstems(x, join_col = NULL, join_col_type = NULL)

Arguments

x

data.frame or sf containing an identifier column joinable to NHDPlusV2 or NHDPlusHR.

join_col

character name of the identifier column in x. Detected automatically from comid, featureid, or nhdplusid (any case) if not provided.

join_col_type

character one of "nhdpv2" or "nhdphr". Detected automatically from join_col if not provided.

Value

x with mainstem_uri and mainstemid columns added.

Details

Source data comes from the ref_rivers GitHub release here. The csv source data is downloaded once, converted to parquet, and cached in the user data dir indicated by hydrogeofetch_data_dir.

The NHDPlusV2 lookup csv is roughly 120 MB and the NHDPlusHR lookup roughly 50 MB, so the mainstem functions have no examples. The first call for a given type downloads and converts the table; later calls in the same session read a cached parquet file and are fast.


old_dir <- hydrogeofetch_data_dir()
hydrogeofetch_data_dir(file.path(tempdir(), "mainstems"))

add_mainstems(data.frame(comid = c(2804607, 2804621)))

hydrogeofetch_data_dir(old_dir)