Skip to main content
2 of 7
edited tags; edited title
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Using Loop with Raster Calculator in ArcPy?

I am trying to loop through multiple rasters and extract cells that are above 0.1 The code I am trying to use is:

import arcpy 
arcpy.CheckOutExtension('Spatial')
arcpy.env.workspace=r'F:\Sheyenne\Atmospherically Corrected Landsat\Indices\Main\NDWI\main_master'
#pathway to all rasters in workspace directory
rasters = arcpy.ListRasters('*.tif*')
for raster in rasters:
     #give new file a name
     outraster = raster.replace('.tif','_water.tif')
     arcpy.gp.RasterCalculator_sa("""raster >= 0.1""",outraster)
print('Done Processing')

but this returns a really long error that doesn't mean much to me.

spotter
  • 101
  • 1
  • 5
  • 13