import arcpy from arcpy import env from arcpy.sa import * #Get Max and Min gridMaxResult = arcpy.GetRasterProperties_management("RASTER1", "MAXIMUM") gridMinResult = arcpy.GetRasterProperties_management("RASTER1", "MINIMUM") #Assign output gridMax = gridMaxResult.getOutput(0) gridMin = gridMinResult.getOutput(0) #Rescale or 'normalize' OutRas = (((Raster("RASTER1") - gridMin) * (1 - 0)) / (gridMax - gridMin)) + 0 OutRas.save("NormalizedRas")
Solved! Go to Solution.
What would the syntax of this code look like if i were to make it a python script to import as a script tool with input and output parameters?
import arcpy from arcpy.sa import * inRaster = arcpy.GetParameterAsText(0) # input raster layer name or raster dataset path outRaster = arcpy.GetParameterAsText(1) # output: raster dataset ras = Raster(inRaster) range = ras.maximum - ras.minimum mappedras = (ras - ras.minimum) / range mappedras.save(outRaster)
It is reading the variable correctly (gridMin is equal to 0) but it seems like it doesnt know it is a numberThat's because it isn't a number.
>>> type(gridMax) <type 'unicode'> >>> gridMax = float(gridMaxResult.getOutput(0)) >>> gridMin = float(gridMinResult.getOutput(0))
I am just trying to 'scale' my raster from 0-1
from arcpy.sa import * rasPath = "RASTER1" ras = Raster(rasPath) print ras.minimum print ras.maximum
range = ras.maximum - ras.minimum mappedras = (ras - ras.minimum) / range mappedras.save("RASTER1_MAP") # save as permanent raster
mappedras = Slice(ras, 1001, "EQUAL_INTERVAL", 0) * .001
What would the syntax of this code look like if i were to make it a python script to import as a script tool with input and output parameters?
import arcpy from arcpy.sa import * inRaster = arcpy.GetParameterAsText(0) # input raster layer name or raster dataset path outRaster = arcpy.GetParameterAsText(1) # output: raster dataset ras = Raster(inRaster) range = ras.maximum - ras.minimum mappedras = (ras - ras.minimum) / range mappedras.save(outRaster)