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
while rasRow:
     rasvol=rasvol + rasCount*rasValue*cellarea

This code is correct or not for calculating the volume ?


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.

| improve this answer | |
  • Sorry I could not get what I was expecting – Ja Geo May 3 '13 at 19:33
  • I have written code to find the volume. Actually I have raster image of water depths. My image resolution is 30*30. Now I need volume of water – Ja Geo May 3 '13 at 19:34
  • Please check my below code whether it is correct to solve my problem or not..please give me feedback – Ja Geo May 3 '13 at 19:44
  • I have tried to numpy arry but i don't know why i am getting negative result ? – Ja Geo May 16 '13 at 3:32
  • Are depths negative values in your raster file? – JeremyFon May 16 '13 at 11:19

Convert the raster to a polygon so you can calculate the area of the raster. Then convert the raster to a point shapefile to calculate the average depth. The volume is the area multiplied by the average depth.

| improve this answer | |
  • The original question asks how to do this in Python, though your approach sounds reasonable. – John Powell Apr 22 '15 at 15:52
  • There are two potential problems with this approach. One is that it is unnecessarily complicated and computationally intensive, given that the same calculations are readily carried out in raster format with no conversion: it's a straightforward zonal sum. The subtler problem is that if the projection is not equal-area and the raster covers a large region, then the average depth will not be the correct value to use. – whuber Apr 22 '15 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.