[GIS] Reclassification of raster

arcpyreclassifyspatial-analyst

Is there a better way to do this?

I'm trying to create a script that will change classifications of a raster to:

0 for: 0,7-9,15-20,40,62-63,73,78-87,89-130,132-151,153-175,177-203,215,228,251-253

1 for: all others

#RECLASSIFY LANDCOVER
#Considers 0 for:  63,81-83,87,111-112,121-124,141-143,190,195,     
#Considers 1 for:  All others.
#Considers "NODATA" for:  background, blank
import arcpy
from arcpy import env  
from arcpy.sa import *
env.workspace = r'C:\Erosion\LandCover'
outReclass1 = Reclassify("CDL_2014.tif", "Value", 
                         RemapRange([[0,0,"NODATA"],[7,9,"NODATA"],[15,20,"NODATA"],[40,40,"NODATA"],
                                     [62,62,"NODATA"],[63,63,0],[73,73,"NODATA"],[78,80,"NODATA"],[81,83,0],
                                     [84,86,"NODATA"],[87,87,0],[89,91,"NODATA"],[93,110,"NODATA"],[111,112,0],
                                     [113,120,"NODATA"],[121,124,0],[125,130,"NODATA"],[132,140,"NODATA"],
                                     [141,143,0],[144,151,"NODATA"],[153,175,"NODATA"],[177,189,"NODATA"],
                                     [190,190,0],[191,194,"NODATA"],[195,195,0],[196,203,"NODATA"],
                                     [215,215,"NODATA"],[228,228,"NODATA"],[251,253,"NODATA"]]), 1)
outReclass1.save(r'C:\Erosion\Output\CDL_reclass.tif')

I was attempting to modify the script from the ArcGIS Resource Center Desktop Help.

Best Answer

You should save the output raster to a raster format, not to a geodatabase, e.g.:

outReclass1.save(r"C:\output\reclass.tif")

EDIT: And there is a missing bracket in the Reclassify line (RemapRange is enclosed but not Reclassify). I've updated my code as well.

You can also simplify the remap parameter a little bit by using the missing_values parameter for all other values that must be remapped to 1:

outReclass1 = Reclassify("raster.tif", "Value", 
                         RemapRange([[0,0,0],[7,9,0],[15,20,0],
                                     [40,40,0],[62,63,0],[73,73,0],[78,87,0],
                                     [89,130,0],[132,151,0],[153,175,0],
                                     [177,203,0],[215,215,0],[228,228,0],[251,253,0]]), 1)

See the Reclassify help page for more details and examples.

Related Question