Dear Arcpy Users,
I am reclassifying my raster data but I cannot get the output that I want. The case is, I have a floating point raster, in which, I want to reclassify it into categorical values. It is quite weird that some of my values are reclassified outside the range of values that I set. For instance,
output categorical raster original raster
1 1.24941356103
1 0.944287159553
1 0.70514940818
0 0.0177492300117
0 2.72532446104e-07
250 -6.0889773748
This is the reclassification method that I want to do.
-50 to -2.58 = 6
-2.58 to -1.96 = 5
-1.96 to -1.65 = 4
-1.65 to -1.29 = 3
-1.29 to 2.58 = 2
2.58 to 50 = 1
other pixels = No data
Here is the code that I am running.
import arcpy, os, sys
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
arcpy.env.extent = "MAXOF"
arcpy.env.workspace = r'directory\of\rasters\test'
rasters = arcpy.ListRasters("*","TIF")
out_ws = 'output/directory/Reclass/'
if not os.path.exists(out_ws):
os.makedirs(out_ws)
for raster in rasters:
name, ext = raster.split(".")
fileout = out_ws + name + "_reclass" + ".tif"
outReclass = Reclassify(raster, "Value", RemapRange([[-50.0,-2.58,6],[-2.58,-1.96,5],\
[-1.96,-1.65,4],[-1.65,-1.29,3],[-1.29,2.58,2],[2.58,50.0,1]]),"NODATA")
outReclass.save(fileout)
Solved! Go to Solution.
looks fine, but try removing the \ at the end of the first line in your RemapRange list, it is
nt needed or wanted
looks fine, but try removing the \ at the end of the first line in your RemapRange list, it is
nt needed or wanted
A really nice feature of python is that if you are inside ( ) or [ ], newlines will be ignored.
Isn't Python, just, well, beautiful?
remap = RemapRange([[-50.0, -2.58, 6], [-2.58, -1.96, 5], [-1.96, -1.65, 4], [-1.65, -1.29, 3], [-1.29, 2.58, 2], [2.58, 50.0, 1]]) out_reclass = Reclassify(raster, "Value", remap, "NODATA")