# Batch processing Surface volume calculation in ArcMap?

I'm trying to collect the 2D area, 3D area and volume of a given basin at 0.5 meter increment in plane height, but since I want to graph the relationship between plane height and the areas and volume, i want to collect many many points.

Doing this one by one is tedious. I'm wondering whether there is a python code that allows me to process a whole bunch of plane heights at once and congregate results in one .txt file or excel file.

currently, the code I'm using is

import arcpy
text="c:\\document\riverside\text.txt"
arcpy.SurfaceVolume_3d("watersheddem",text,"BELOW",250,1,1)


but this code only allows me to read result on the side bar, when i actually check the text.txt file it is empty even when my arcpy.surfacevolume_3d was ran successfully.

• Welcome to GIS SE! As a new user be sure to take the Tour. It may just be the way you have formed your pathname - try text=r"c:\document\riverside\text.txt". – PolyGeo Sep 4 '15 at 4:00
• see your GeoNet post for further comments – user681 Sep 4 '15 at 4:08

This tool will loop through a range of user-defined values and write the outputs to a text file. You can get the Arctoolbox tool version here https://github.com/gerry1138/ArcGIS-Loop-Surface-Volumes

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

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"
return thevaluesatx

#My_txt = r"Z:\GISpublic\GerryG\aaaa.txt"
#My_surface= r"I:\SurfaceModels\USGS_DEM\ldeltagrid5ft"
#direction = "above"
#startingplane = 0
#z = 1
#y = .5
#q = 2

My_surface= arcpy.GetParameterAsText(0)
My_txt = arcpy.GetParameterAsText(1)
direction = arcpy.GetParameterAsText(2)

startingplane = float(arcpy.GetParameterAsText(3))
z = float(arcpy.GetParameterAsText(4))
endingplane = float(arcpy.GetParameterAsText(6))

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

if direction == "BELOW":

while startingplane > endingplane:
result = arcpy.SurfaceVolume_3d(My_surface, "", direction, startingplane, z)
thevaluesatx = GetValues(result.getMessages(0), startingplane)
f.writelines(thevaluesatx)

if direction == "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)

f.close()