import arcpy, os, sys from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("Spatial") arcpy.env.workspace = r'E:\Test_awd\awd_pct' # Raster workspace raster_ws = r'E:\Test_awd\awd_pct' # Getting the list of raster dataset arcpy.env.workspace = raster_ws rasters = [os.path.join(raster_ws, r) for r in arcpy.ListRasters()] #Output workspace raster_ow = r'E:\Test_awd\awd_pct' # Get dictionary (raster1:value, ..., raster5:value) rastVal = {"RE_suitable_dek001":11.2,"RE_suitable_dek002":14.9, "RE_suitable_dek003":9.4, "RE_suitable_dek004":10.4, "RE_suitable_dek005":12.4} # Raster map algebra for rast in rastVal: # Iterate to all raster in the directory outRaster = os.path.join(raster_ow, os.path.basename(rast)) # output path and filename of my raster if rast in rastVal: # iterate my raster if in the dictionary outRaster = rasters / rastVal[rast] * 100 # the equation that I want to execute...(raster1/11.2)*100 outRaster.save(outRaster + "pct") # output raster with pct (percentage) suffix else: print "ERROR: No matching entry in raster value look up dictionary!"
Solved! Go to Solution.
for rast in rastVal:
for rast in rasters:
outRaster = Raster(rast) / rastVal[rast] * 100
rasters = [os.path.join(raster_ws, r) for r in arcpy.ListRasters()]
rastVal = {"RE_suitable_dek001":11.2,"RE_suitable_dek002":14.9, "RE_suitable_dek003":9.4, "RE_suitable_dek004":9.4, "RE_suitable_dek005":9.4}
for rast in rastVal: # Iterate to all raster in the directory outRaster = os.path.join(raster_ow, os.path.basename(rast)) # output path and filename of my raster if rast in rastVal: # iterate my raster if in the dictionary outRaster = Raster(rast) / rastVal[rast] * 100 # the equation that I want to execute...i.e., (raster1/11.2)*100 outRaster.save(outRaster + "pct") # output raster with pct (percentage) suffix else: print "ERROR: No matching entry in raster value look up dictionary!"
for rast in rastVal: # Iterate to all raster in the directory outRaster = os.path.join(raster_ow, os.path.basename(rast)) # output path and filename of my raster if rast in rastVal: # iterate my raster if in the dictionary outRaster = arcpy.Raster(rast) / rastVal[rast] * 100 # the equation that I want to execute...i.e., (raster1/11.2)*100 outRaster.save(outRaster + "pct") # output raster with pct (percentage) suffix else: print "ERROR: No matching entry in raster value look up dictionary!"
for rast in rastVal:
for rast in rasters:
outRaster = Raster(rast) / rastVal[rast] * 100
I also change the name of my rasters to the fullpath:
RE_suitable_dek001:9.4 to r'Fullpath\RE_suitable_dek001:9.4
I also read this method in your post but I think you have already removed it in the thread.
rasters = [os.path.join(raster_ws, r) for r in arcpy.ListRasters()]