-
-
Save ryan-hill/a81b471920531e680859c692d24930bb to your computer and use it in GitHub Desktop.
recursive function to walk up flow table. NOTE: this will not handle braided flowlines!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from StreamCat_functions import dbf2DF | |
pre = 'D:/NHDPlusV21/NHDPlusGL/NHDPlus04' | |
fline = dbf2DF('D%s/NHDSnapshot/Hydrography/NHDFlowline.dbf' % pre) | |
flow = dbf2DF('%s/NHDPlusAttributes/PlusFlow.dbf' pre)[['TOCOMID','FROMCOMID']] | |
def recurs(val, ups): | |
print val | |
ups = ups + flow.ix[flow.TOCOMID == val].FROMCOMID.tolist() | |
if 0 in ups: | |
ups.remove(0) | |
# here is where you would calculate whatever value that you want to pass through | |
area = fline.ix[fline.COMID == val].LENGTHKM.values[0] | |
# in this case I just grabbed length of the flowline | |
if ups: | |
return area + recurs(ups.pop(), ups) | |
else: | |
return area | |
recurs(4796914,[]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment