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") # Select correct interpolated rasters for lyr in aprx.listMaps()[0].listLayers(): if lyr.isRasterLayer: if 'Temp' in lyr.name: if 'Int_Raster' in lyr.name: # Set local variables raster = Raster(lyr.dataSource) thresholds = [14, 23] bounds = [14, 23] scale = [1, 0.496714] transformation = TfLinear( bounds[0], bounds[1], thresholds[0], 1, thresholds[1], 0 ) outName = arcpy.env.scratchWorkspace + "\\" + raster.name.replace('Int_Raster','Resc') # Rescale the raster rescaledRaster = RescaleByFunction( raster, transformation, scale[0], scale[1] ) # Save the rescaled raster rescaledRaster.save(outName) #NOT WORKING!!! print(rescaledRaster.isTemporary) print(rescaledRaster.name)
save is not saving the 'raster', you should be saving 'rescaledRaster'
rather than trying to fiddle around with the name before you process it... rename it after it is saved
Am I not already saving 'rescaledRaster' with rescaledRaster.save(outName)? I've tried the following as well, which is what I think you're suggesting:
name = inRaster.name.replace('Int_Raster','Resc')
rescaledRaster.save()
arcpy.Rename_management(rescaledRaster, name)
I've done it with and without the following addition beforehand, as per this thread.
arcpy.env.overwriteOutput=True
if arcpy.Exists(outName):
arcpy.Delete_management(outName)
I get the following error message regardless:
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
The table already exists. [name]
Failed to execute (Rename).
("name" is the actual name, not the variable). I cannot do
arcpy.Rename_management(rescaledRaster, outName)
or else I get this:
ERROR 000670: output Output Data is same as input Input Data Element
Throw in some print statements to make sure that the name is correct. I can't tell from the code
Hello All -- I still have the same problem and wondering if anyone has solved the issue with .save throwing the RuntimeError: ERROR 999998: Unexpected Error..