Access "Accumulate Attributes" in model or Python

2890
9
07-14-2011 04:08 AM
ErikMartin
Occasional Contributor
Is there a way to access the ArcHydro "Accumulate Attributes" tool through either a model or Python?  The tool is on the toolbar and is working well for my purposes, but I am trying to automate the processing of many operations and I don't see it available in the ArcHydro toolbox, nor do I see Python syntax anywhere.  I am using ArcGIS 10 and ArcHydro 2.0.1.75.

Thanks,
-Erik
Tags (2)
0 Kudos
9 Replies
JoannaMerson
New Contributor
Did you ever find an answer for this?
Thanks!

PS enjoy: http://www.xkcd.com/979/
0 Kudos
PeterWilson
Occasional Contributor III
Hi Erik

There is currently no way to achieve this either by scripting or model bulder. The reason for this is that you can't access the tool via the toolbox. You would have write your own tool to perform the same process using either python or C#.

Regards
0 Kudos
ErikMartin
Occasional Contributor
Thanks, I thought that may be the case.
0 Kudos
JonWalker
New Contributor
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
0 Kudos
ErikMartin
Occasional Contributor
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


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...
0 Kudos
JonWalker
New Contributor
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...


Hey Erik - thanks for the response, I just noticed it.  I would definitely be interested in seeing that script, as well as in any useful instructions for its use that you'd like to share.

Jon
0 Kudos
NareshPai
New Contributor
Hey Erik,

Can I get a copy of your script? I am trying to accumulate attributes in a polygon shapefile with 84k records and my estimate is that it will take weeks to complete.

Thanks,
Naresh
0 Kudos
JonWalker
New Contributor
Hey Erik,

Would you mind posting your script?  Thanks!

Jon
0 Kudos
ErikMartin
Occasional Contributor
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)