# 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
– 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.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()
{"ft_lang_label":"__label__en","ft_lang_prob":0.91571903,"math_prob":0.86719084,"size":792,"snap":"2021-43-2021-49","text_gpt3_token_len":198,"char_repetition_ratio":0.09898477,"word_repetition_ratio":0.0,"special_character_ratio":0.23106061,"punctuation_ratio":0.14201184,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9824655,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-23T23:29:22Z\",\"WARC-Record-ID\":\"<urn:uuid:427503eb-2fd8-4dc7-b2d9-467e4dd4fb72>\",\"Content-Length\":\"169242\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b4c204b2-9536-4c07-83ed-52403d25f0b9>\",\"WARC-Concurrent-To\":\"<urn:uuid:7063b5c4-1376-4708-aacb-5f396fc99ceb>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://gis.stackexchange.com/questions/161795/batch-processing-surface-volume-calculation-in-arcmap\",\"WARC-Payload-Digest\":\"sha1:QTM5IKTRBRBT4N6AQKOGYWRD44GKN3D3\",\"WARC-Block-Digest\":\"sha1:2KM2RMKY7XRAGZC6XXIOVQMKCPYUAONF\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585828.15_warc_CC-MAIN-20211023224247-20211024014247-00026.warc.gz\"}"}