3

I am trying to use Reclassify on 240 rasters using ArcPy within the Python window in ArcMap 10.7. My original raster has continuous decimal probabilities ranging from 0 to 1, and my goal is to change everything above 0.5 to 1 and everything at or below 0.5 to 0.

The code executes the reclassification, but it leaves some cells out and misclassifies others, even though those cells are well within the range of values addressed in the reclassification remap. For example, sometimes cells with a value of 0.42 are reclassified as 1, and cells with a value of 0.67 are set to 0.

When manually doing Reclassify using the Spatial Analyst toolbox, all cells are reclassified correctly and none are missed. I copied the python snippet from the Results of that manual reclassification, so I'm not sure why when I execute the same code, it produces incorrect results. There does not appear to be any pattern in the errors; they span the full range of the original raster values. Does anyone know why these cells are getting left out and why other cells are inaccurately classified?

from arcpy import env
from arcpy.sa import *
arcpy.env.workspace = r"C:\Users\Me\Documents\Myworkspace"
RasterList = arcpy.ListRasters("*.tif")
for raster in RasterList:
    outreclass1 = arcpy.gp.Reclassify_sa(raster, "VALUE", "0 0.500000 0;0.500000 1 1", "DATA")) 
    #format for Reclassify is the same as python snippet from Results of manual reclassification

In the output screenshot, the red and blue cells are from the original raster (bottom layer) that were left out of the Reclassified raster output (yellow and green cells; top layer). White = NoData.

Reclassified raster overlaid on original raster

5
  • You've given some example values in your original raster and they are to 2 decimal places, is that really the case? Explore the values that are not being reclassified are they to some unusual X number of decimal places?
    – Hornbydd
    Commented Feb 22, 2021 at 22:42
  • The raster goes out to 6 decimal places, and so does the Reclassify command.
    – Mon Mo
    Commented Feb 22, 2021 at 23:41
  • You could try Con - outreclass1 = arcpy.sa.Con(raster > 0.5,1,0) which might get you out of trouble for now. Although using arcpy.gp is still essentially correct the newer functions using arcpy.sa tend to be more advanced, the arcpy.sa.Reclassify resources.arcgis.com/en/help/main/10.2/index.html#//… uses a arcpy.sa.RemapRange object for the remap argument so outreclass1 = arcpy.sa.Reclassify(raster,arcpy.sa.RemapRange([[-2,0.5,0],[0.5,2,1]] gives you the option of many remap values and then outreclass1.save(r'D:\your\full\path\to\raster.ext') to persist to disc. Commented Feb 23, 2021 at 5:14
  • outreclass1 = Con(raster, 1, 0, "VALUE > 0.500000") and outreclass1 = arcpy.sa.Reclassify(raster, "Value", arcpy.sa.RemapRange([[0, 0.500000, 0],[0.500000,1,1]])) produce the same results as before.
    – Mon Mo
    Commented Feb 23, 2021 at 20:14
  • I didn't get anywhere with this in ArcMap, so I switched to using R for reclassification, which worked correctly.
    – Mon Mo
    Commented Mar 15, 2021 at 19:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.