I'm trying to do Map Algebra on a bunch of rasters by iterating through a for loop and saving them in an empty geodatabase. However, they aren't saving properly. Only the last raster is created and it is named "rescaledRaster" rather than the outName. Here's the code:
import arcpy, os
from arcpy.sa import *
arcpy.env.workspace = r"[abspath]"
arcpy.env.scratchWorkspace = r"[abspath]\rescale.gdb"
aprx = arcpy.mp.ArcGISProject(r"[abspath]\filename.aprx")
for lyr in aprx.listMaps().listLayers():
if 'Temp' in lyr.name:
if 'Int_Raster' in lyr.name:
raster = Raster(lyr.dataSource)
thresholds = [14, 23]
bounds = [14, 23]
scale = [1, 0.496714]
transformation = TfLinear( bounds, bounds, thresholds, 1, thresholds, 0 )
outName = arcpy.env.scratchWorkspace + "\\" + raster.name.replace('Int_Raster','Resc')
rescaledRaster = RescaleByFunction( raster, transformation, scale, scale )
The print statements seem correct each time; .isTemporary comes out False and .name returns the outName. Despite this, the output rasters keep getting overwritten.
I also tried outName = os.path.join(arcpy.env.scratchWorkspace, raster.name.replace('Int_Raster','Resc')) already and that didn't work either.