2

I have never coded in Python before and I am trying to loop a simple map algebra equation across 365 rasters. I am trying to calculate total water flow over cells but in the raster I have a negative value to indicate the water table is below ground: for my purposes those cells should read 0. I have tried to write a for loop but it does not seem to be working. Python does not throw any errors, but the output data set still has negative numbers. Any suggestions on why the loop isn't working to remove the negative values?

arcpy.env.workspace="C:/..../2013_q1_tiff_v2prov"
Fcs= arcpy.ListRasters() 
From arcpy.sa import *
from arcpy.sa import *
print Fcs

for Raster in Fcs:
    Con(Raster <0, 0, Raster)

pleasework= CellStatistics(Fcs, "SUM")
  • Do you want to SUM overlapping cells in all rasters? – Ibe Mar 28 '14 at 4:40
1

This is because you are still referring to the original rasters when providing "Fcs" to the CellStatistics function. You need to store the results of your conditional statement and then refer to those, so something like this should work:

con_rasters = list()
for Raster in Fcs:
    temp_raster = Con(Raster <0, 0, Raster)
    con_rasters.append(temp_raster)

pleasework= CellStatistics(con_rasters, "SUM")
  • Thanks for the response Chad! Unfortunately it still looks like the conditional statements is not being applied to the temp_raster It will write a new temp raster but the <0 values are still there. If it helps to trouble shoot how python is reading my code the temp_rasters are written as ifthe_ras, ifthe_ras1..ect. Thanks again for the response! – Adia Mar 27 '14 at 19:00
  • When you say that the < 0 values are still there, do you mean in the output of CellStatistics or in the temp rasters? – Chad Hawkins Mar 27 '14 at 20:39

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.