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

#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", 
                                     [215,215,"NODATA"],[228,228,"NODATA"],[251,253,"NODATA"]]), 1)

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

  • 4
    Define better: is the listed method slow, does it not work, are the values wrong? You could also use Reclassify by Table: resources.arcgis.com/en/help/main/10.1/index.html#//…, your values go into a table so you can reuse it. – Michael Stimson Mar 24 '15 at 4:46
  • @Michael Says invalid syntax on the last line. – rnr0004 Mar 24 '15 at 6:19
  • 1
    An attractive alternative to consider is InList. The syntax is clearer and more congenial. I haven't tested the performance relative to the other reclassification methods. – whuber Mar 24 '15 at 14:58
  • outReclass1.save(r'C:\output.gdb\RasterName'), you don't just need to tell it where you must also supply a dataset name. If you're saving to a folder location then you should include file extension, if you don't it will try to save as GRID which has severe limitations. – Michael Stimson Mar 24 '15 at 21:01
  • 2
    It's not bad you just can't save a file source (like tif, jpg, ecw, shp...) in a geodatabase. Everything that's stored in a geodatabase is a geodatabase type: Geodatabase Feature class, Geodatabase Raster... those types don't have extensions and you need ArcCatalog etc. just to see them. – Michael Stimson Mar 24 '15 at 21:32

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


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", 
                                     [177,203,0],[215,215,0],[228,228,0],[251,253,0]]), 1)

See the Reclassify help page for more details and examples.

  • Still getting, "Parsing error SyntaxError: invalid syntax (line 10)" - which is for the outReclass1.save(r"C:\output\reclass.tif") – rnr0004 Mar 24 '15 at 12:12
  • Running it in IDLE shows outReclass1 in red. @GISGe – rnr0004 Mar 24 '15 at 13:44
  • What do you mean? If you have a closing bracket missing, the error will show up farther in the code, where it is expected to be found (not where it is actually missing). – GISGe Mar 24 '15 at 13:48
  • I got it working. Thanks. Only now it says, "The input raster minimum (1) is out of range. To ensure a correct reclassification, edit ranges or use a different precision settings in the Reclassification dialog box. The input raster maximum (238) is out of range. To ensure a correct reclassification, edit ranges or use a different precision settings in the Reclassification dialog box." – rnr0004 Mar 24 '15 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.