I am facing this error time and again when I am try to read my img rasters and running a conditional statement. I am new to Python. The code ran for one raster that is without for loop but not later. Here is the code:
import arcpy, os
from arcpy import env
from arcpy.sa import *
env.overwriteOutput = True
arcpy.env.workspace = r"C:\Users\libpub\Desktop\try"
arcpy.CheckOutExtension('Spatial')
rasterlist = arcpy.ListRasters()
for raster in rasterlist:
out1 = Con(('Raster')>0.2, 1, 0)
print out1
out1.save("C:\Users\libpub\Desktop\try")
print "done!"
Best Answer
The
arcpy.ListRasters
function returns a list of the raster names in your workspace. TheCon
function, in the format you are using, requires an input Raster object which can be created with:If you change
out1 = Con(('Raster')>0.2, 1, 0)
toout1 = Con(Raster(raster)>0.2, 1, 0)
you should find it works. This is shown in theCon
documentation in code example 1.