9 Replies Latest reply on Oct 28, 2013 10:07 AM by ehm119

    Access "Accumulate Attributes" in model or Python

    ehm119
      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
        • Re: Access "Accumulate Attributes" in model or Python
          jomerson
          Did you ever find an answer for this?
          Thanks!

          PS enjoy: http://www.xkcd.com/979/
          • Re: Access "Accumulate Attributes" in model or Python
            Playa
            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
            • Re: Access "Accumulate Attributes" in model or Python
              ehm119
              Thanks, I thought that may be the case.
              • Re: Access "Accumulate Attributes" in model or Python
                jaydubbbbbb
                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
                • Re: Access "Accumulate Attributes" in model or Python
                  ehm119
                  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...
                  • Re: Access "Accumulate Attributes" in model or Python
                    jaydubbbbbb
                    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
                    • Re: Access "Accumulate Attributes" in model or Python
                      npai
                      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
                      • Re: Access "Accumulate Attributes" in model or Python
                        jaydubbbbbb
                        Hey Erik,

                        Would you mind posting your script?  Thanks!

                        Jon
                        • Re: Access "Accumulate Attributes" in model or Python
                          ehm119
                          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)