Skip to main content
4 of 7
edited tags
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')

For some reason I can't copy and paste the error (python actually shuts down when I run this code) but here is a screen shot of part of it.

enter image description here

spotter
  • 101
  • 1
  • 5
  • 13