Confluence Retirement

In an effort to consolidate USGS hosted Wikis, myUSGS’ Confluence service is scheduled for retirement on January 27th, 2023. The official USGS Wiki and collaboration space is now SharePoint. Please migrate existing spaces and content to the SharePoint platform and remove it from Confluence at your earliest convenience. If you need any additional information or have any concerns about this change, please contact Thank you for your prompt attention to this matter.
Skip to end of metadata
Go to start of metadata

Introduction of processing logic

The purpose of this work was to create accumulated watershed boundaries for each 12-digit HUC in the watershed boundary dataset. The work started in July 2015 shortly after the WBD team completed a major cleanup of the TOHUC codes.

There are three functions that have significant logic in them. 1) fromHUC_finder, 2) HUC_aggregator, and 3) unionHUC.

1) Given a list of TOHUCs and a HUC to analyze, fromHUC_finder returns all the HUCs that flow into the HUC in consideration.

2) Given a HUC to analyze and all the potential fromHUC lists upstream of it, HUC_aggregator recursively walks the fromHUC list upstream collecting as it goes.

3) Given a HUC to analyze, it's list of upstream HUCs from HUC_aggregator, and the contents of a shapefile of the local HUC boundaries in an R spatialPolygons format, unionHUC selects and aggregates all the polygons into a single polygon.

A fourth function is included in the package. It is a runner function for use with a parallelized function like parApply. It is a stand alone orchestration function to be run in a new R environment and has no significance other than allowing the code to run on many CPUs controlled from a single instance running the snow parallel R package.

Access to source code


For the sake of putting the kernel of this inline, here's the recursive function.

Recursive Code
  fromHUCs<-fromHUC[[huc]] # Get fromHUCs list for given huc
  if(any(huc %in% fromHUCs)) { # found some HUCs that have themselves as a toHUC
    print(paste('found circular reference in',huc))
  if(length(fromHUCs)==0) { # If no fromHUCs for given HUC, return aggHUCs.
  else { # Otherwise, add current list to aggHUCs and call HUC_aggregator for list of upstream HUCs.

Output table

  • No labels

1 Comment

  1. A lot of this links no longer work.