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)
Don't know if you're still looking for this, but I ended up scripting something using the Geometric Network tools (available as a toolbox in 10.1) and an arcpy.da cursor. It takes a while to run (~30hours to run my stream network of 410,000 segments) but that's actually a little faster than the performance I was getting using ArcHydro's Accumulate Attributes. Let me know if you're still interested...
I notice the last post on this topic was from January. Has anybody come across a script that can automate the accumulate attributes process? Jon
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.