Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 ?

share|improve this question

2 Answers 2

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.

share|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.

share|improve this answer
    
The original question asks how to do this in Python, though your approach sounds reasonable. –  John Barça Apr 22 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 at 16:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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