assumes that each network feature has a "downId" value (see these pages for guidance on that).
assumes that entire network can be dumped to an array in Python.
does not assume any proprietary GIS platform
just an enhanced version of Finding upstream flowlines - recursion (Python)
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 feature identifier, id, and 2) the identifier of the downstream feature, downId. The array is "typed", meaning that the columns have names (strings).
If there are any features whose downId points to the id, then the function will call itself once for each inflowing neighbor using that neighbor's id as the id argument. If there is a feature 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 id (i.e., that the current flowline feature is a headwater). The final product of the function is the networkArr, but that has updated attributes. Note that the initial version of networkArr should provide an accumulation field (charAccumField) that is initialized to the charField on the first iteration.
Note that this sample does not include any code to write results to a file or back to a GIS format. Pretty basic, but you'll still need to deal with that (at least until this or a link page gets updated).
Below is an example of some arcpy code for extracting the relevant information from a featureclass, as well as the invocation of the accumulation method. Note that the field to be accumulated ('SHAPE@LENGTH') is arbitrary.
|Wieczorek, Michael E.||0||1||0|