Given flowlines with fromnode and tonode attributes, will return a toid attribute that is the result of joining tonode and fromnode attributes. In the case that a terminalpa attribute is included, the join is executed by terminalpa group. This is done grouped by terminalpathID because duplicate node ids have been encountered across basins in some datasets. If `remove_coastal` is `TRUE` (the default) either ftype or fcode are required. Uses the add_toids function.

  return_dendritic = TRUE,
  missing = 0,
  remove_coastal = TRUE,
  add = TRUE



data.frame with comid, tonode, fromnode, and (optionally) divergence and terminalpa attributes.


logical if TRUE, a divergence attribute is required (2 indicates diverted path, 1 is main) and diverted paths will be treated as headwaters. If this is FALSE, the return value is a data.frame including the comid and tocomid attributes.


integer value to use for terminal nodes.


logical remove coastal features prior to generating tocomid values? ftype or fcode are required if `TRUE`. fcode == 56600 or fcode == "Coastline" will be removed.


logical if TRUE, a tocomid column will be added, otherwise a data.frame with two columns will be returned.


data.frame containing comid and tocomid attributes or all attributes provided with comid and tocomid in the first and second columns..


source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))

tocomid <- get_tocomid(sample_flines)

tocomid <- get_tocomid(sample_flines, return_dendritic = FALSE)