Sorry for the long delayed response-- thanks for the reminder jaydubbbbb. Here's the script, and attached is a toolbox with a tool w/ parameters all set up to work with it. It uses the geometric network tools, so Arc 10.1 or greater is needed. There's some basic metadata in the tool description.Each line segment is looped through, so it takes a little while to run. My dataset with ~400,000 records took between a day and a day and a half to run.-Erik
import arcpy
Workspace = "in_memory"
arcpy.env.overwriteOutput = True
arcpy.env.workspace = Workspace
#variables
network = arcpy.GetParameterAsText(0)
netHydroFC_path = arcpy.GetParameterAsText(1)
nonNetHydroFC = arcpy.GetParameterAsText(2)
accumSourceField = arcpy.GetParameterAsText(3)
accumTargetField = arcpy.GetParameterAsText(4)
calculateMe = arcpy.GetParameterAsText(5)
#get the text name of the network FC without the full path by taking what's after the last "\"
netHydroFC = netHydroFC_path.split("\\")[-1].strip()
#list fields to include in cursor
fields = ("OBJECTID", accumSourceField, accumTargetField)
arcpy.AddMessage("Running...")
#open arcpy.da cursor
with arcpy.da.UpdateCursor(nonNetHydroFC, fields) as rows:
for row in rows:
#get values for each row
rowObjID = row[0]
rowCtchVal = float(row[1])
DAval = float(row[2])
#If there's already an accumulated value skip that record
if DAval <> int(calculateMe):
arcpy.AddMessage("ObjectID " + str(rowObjID) + " is already calculated")
#If the value is equal to the "calculate me" flag run the operation
if DAval == int(calculateMe):
arcpy.AddMessage("Calculating ObjectID # " + str(rowObjID))
#make a feature layer in memory and select the record that is active in the cursor
arcpy.MakeFeatureLayer_management(nonNetHydroFC, "sel_lyr")
selection = '"OBJECTID" = {}'.format(rowObjID)
arcpy.SelectLayerByAttribute_management("sel_lyr", "NEW_SELECTION", selection)
#create a point at the start vertex of the selected record
arcpy.FeatureVerticesToPoints_management("sel_lyr", "flag", "START")
#select the upstream network & take the line layer from the returned layer group (network + junctions)
flag = "flag"
arcpy.TraceGeometricNetwork_management(network, "netLayer", flag, "TRACE_UPSTREAM")
usSelection = arcpy.SelectData_management("netLayer", netHydroFC)
field = accumSourceField
usVals = [r[0] for r in arcpy.da.SearchCursor(usSelection, (field))]
sumUSVals = float(sum(usVals))
newDAVal = float(sumUSVals + rowCtchVal)
row[2] = newDAVal
rows.updateRow(row)