TransWikia.com

Including float value in loop processing of Surface Volume tool using ArcMap ModelBuilder

Geographic Information Systems Asked on August 23, 2021

How do I use the Surface Volume tool in ArcMap via Model Builder, without using Python, to process a set of multiple float values in a loop, since an iterator takes integers when I implement a for loop?

See the attached image as indication.

enter image description here

3 Answers

An alternative method is to create a table and store your floats in that, 1 row per float value. Then use the Iterate Field Value iterator to drive your model. But I think @user2856 has the simplest solution.

Correct answer by Hornbydd on August 23, 2021

You can use the Iterate Multivalue tool and add a list of floats:

enter image description here

Answered by user2856 on August 23, 2021

Here is the code to loop the surface volume tool. You can hard-code the paths and run this in your favourite IDE. Or un-comment the arcpy.GetParameter....stuff and turn this into a Toolbox Tool.

try:
import sys, arcpy, traceback
arcpy.CheckOutExtension("3D")

arcpy.AddMessage( "Multi-Volumes for ArcGIS 10")
arcpy.AddMessage("Loop the 3D Analyist Surface Volume tools for a range of values...")


def GetValues(themessage, x):
    thevaluesatx = str(x)
    themessage = themessage.split("n")
    thevalues = themessage[2].split("  ")
    for item in thevalues:
        thevalue = item.split("=")
        thevalue = thevalue[-1]
        thevaluesatx = thevaluesatx + "," + str(thevalue)
    thevaluesatx = thevaluesatx +"n"
    arcpy.AddMessage(thevaluesatx)
    return thevaluesatx


My_txt = r"F:FerndaleDirtPile20190729ferndaledirtpipe20190729demUTMvolumes.csv"
My_surface= r"F:FerndaleDirtPile20190729ferndaledirtpipe20190729demUTM.tif"
direction = "ABOVE"
startingplane = 4
endingplane = 10.4
z = 1
graduations = 0.25


#My_surface= arcpy.GetParameterAsText(0)
#My_txt = arcpy.GetParameterAsText(1)
#direction = arcpy.GetParameterAsText(2)
#startingplane = float(arcpy.GetParameterAsText(3))
#z = float(arcpy.GetParameterAsText(4))
#graduations = float(arcpy.GetParameterAsText(5))
#endingplane = float(arcpy.GetParameterAsText(6))

direction  = direction.upper()
f = open(My_txt,'a')
f.writelines(r"elevation, 2d_area, 3d_area, volume" + "n")

arcpy.AddMessage("Please wait, this script is processing...")

if direction == "BELOW":
    arcpy.AddMessage("startingplane = " +str(startingplane))
    arcpy.AddMessage("endingplane = " +str(endingplane))
    
    while startingplane > endingplane:
        arcpy.AddMessage("Getting Results...")
        result = arcpy.SurfaceVolume_3d(My_surface, "", direction, startingplane)
        thevaluesatx = GetValues(result.getMessages(0), startingplane)
        f.writelines(thevaluesatx)
        
        startingplane = startingplane - graduations

if direction == "ABOVE":
    arcpy.AddMessage("Executing above...")
    x = startingplane
    while startingplane < endingplane:
        result = arcpy.SurfaceVolume_3d(My_surface, "", direction, startingplane, z)
        thevaluesatx = GetValues(result.getMessages(0), startingplane)
        print thevaluesatx
        f.writelines(thevaluesatx)
        
        startingplane = startingplane + graduations


f.close()

arcpy.AddMessage("Finished without errors!")

except arcpy.ExecuteError: 
    msgs = arcpy.GetMessages(2) 
    arcpy.AddError(msgs)  
    #If the error is with the script, or with python, find error and report it to the screen...
except:
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:nTraceback info:n" + tbinfo + "nError Info:n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:n" + arcpy.GetMessages(2) + "n"
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)

Answered by GBG on August 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP