import os import arcpy from arcpy import env from arcpy.sa import * # note: we're using os.path.join as a workaround for broken data source errors debug_features = os.path.join('C:\Raster\scripts\Temp.gdb\simple') # Set this to the folder containing all rasters workspace = "C:\Raster\Data" try: # Check out Spatial Analyst License arcpy.CheckOutExtension("Spatial") env.workspace = workspace # Get parameters aoi_layer = arcpy.MakeFeatureLayer_management(debug_features,'in_memory\features') raster_1 = "tmax_1.tif" raster_2 = "tmax_2.tif" # Extract only the area under the feature layer aoi_raster_1 = ExtractByMask(raster_1,aoi_layer) aoi_raster_2 = ExtractByMask(raster_2,aoi_layer) # Add two rasters out_raster = aoi_raster_1 + aoi_raster_2 # Copy to png name = arcpy.CreateUniqueName("rastermath_output.png", arcpy.env.scratchFolder) arcpy.CopyRaster_management(out_raster, name,"DEFAULTS", "","","","","16_BIT_UNSIGNED", "ScalePixelValue") # Set output param arcpy.SetParameterAsText(0, name) except Exception as e: arcpy.AddError(str(e)) finally: arcpy.Delete_management('in_memory')
Solved! Go to Solution.