[GIS] How to calculate volume from a raster file

arcgis-10.0areapythonraster

I have a raster file containing the depth of water. I need to find the volume of water using that raster file. I need to find the area of each cell and multiply with the depth. How can I do it in Python using ArcGIS 10 ?


rasvol = 0
rasterArea=gp.searchCursor(reservoir_area)
rasRow=rasterArea.next()
while rasRow:
     rasCount=rasRow.getValue('Count')
     rasValue=rasRow.getValue('Value')
     rasvol=rasvol + rasCount*rasValue*cellarea
     rasRow=rasterArea.next()

This code is correct or not for calculating the volume ?

Best Answer

If your raster has cells of equal size then the area is easy enough, as its just the cells size squared. Then you could use the Spatial Analyst - Math - Times tool to multiply each cell times its area to get a raster representing the volume for each cell.

import arcpy
from arcpy.sa import *
outVol = Times("depth", "100")

One method to get the total would be to convert the raster to a numpy array and then to just take the sum of that array.

import numpy 
myArray = arcpy.RasterToNumPyArray(outVol)
totVolume= numpy.sum(myArray)

If the cells are of a different size then your best bet might be to convert the raster to a polygon and calculate the area of each cell.

Related Question