I'm running a for loop to rescale a bunch of rasters and then save them for use in another function. However, I'm having trouble saving the rasters properly. My current solution is to copy the rasters so that they have the correct names (they're initially called "numpyarraytoraster_[long unique string of characters]") and then delete the old temporary layer. Using arcpy.Delete_management deletes the extraneous layers but also crashes the program (ArcGIS Pro 2.0.0) on the final iteration. I'd love to know why.
Relevant code, all within a for loop:
name = inRaster.name.replace('Int_Raster','Rescl') outName = os.path.join(arcpy.env.scratchWorkspace, name) # Convert back to raster rescaledRaster = arcpy.NumPyArrayToRaster(rescArray, lowerLeft, cellSize, value_to_nodata=NULL) arcpy.DefineProjection_management(rescaledRaster, 4326) # Save the rescaled raster arcpy.env.overwriteOutput = True if arcpy.Exists(outName + ".lyrx"): os.remove(outName + ".lyrx") copy = arcpy.CopyRaster_management(rescaledRaster, outName) rasLayer = arcpy.MakeRasterLayer_management(copy, name) lyrx = arcpy.SaveToLayerFile_management(rasLayer, outName) #arcpy.Delete_management(rescaledRaster) #causes ArcGIS to crash when not commented out members.append(name)
I'll note that this solution still doesn't allow me to access the rescaled rasters without saving, quitting, and reopening the program, but if I can get it to at least output all the correct rasters with the correct names then I'll be happy.