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

This pattern could be replicated in any language, but is implemented here in Python. It is a tabular manipulation, requiring no GIS software, but relies on the id and idDown attributes to define routing connectivity. 

The hydrographic network is known to the function as a array, networkArr, where each record has two attributes: 1) the flowline identifier, id, and 2) the identifier of the downstream flowline, idDown. The array is "typed", meaning that the columns have names (strings). 

The function will add the starting currComid to the list of all upstream feature identifiers, comidList. If there are any flowlines whose idDown points to the currComid, then the function will call itself once for each inflowing neighbor using that neighbor's id as the currComid argument. If there is a flowline draining into one of the inflowing neighbors, then the function will call itself using that neighbor's id. This process will climb upslope according to the networkArr connectivity, until the networkArr indicates that no records have an idDown value that eqauls the current currComid  (i.e., that the current flowline is a headwater). The final product of the function is the comidList. Note that the client should provide an empty list to the function on the first iteration. 


def findUpstreamFlowlines(currComid, comidList, networkArr, id, idDown):
    inFlowlines = networkArr[networkArr[idDown] == currComid][id]
        for inFlowline in inFlowlines:
            comidList = findUpstreamFlowlines(inFlowline, comidList, networkArr, id, idDown)
    return comidList

Below is an example of some arcpy code for extracting the relevant information from a featureclass.

import arcpy
networkArr = arcpy.da.TableToNumPyArray(myNetworkFeatureClass,
                                        [id, idDown])

Viger, Roland 1100

  • No labels