1

I am trying to reclassify a bunch of rasters, but when I run my script arcGIS crash. What I want to do, is reclassify rasters this way: every accepted value (0,1,5 and 64) to 1, and the others values just assign "NODATA". By this way, every processed raster would be like a binary raster, just values 1 and "NODATA". The value 1 is because I need to multiply this raster with other raster, acting like a mask. Maybe, I need to reclassify to logical raster (TRUE/FALSE values).

I suppose this problem is caused because every raster could have or not all accepted values, so when I run my script, the actual raster perhaps don't have one of the accepted values, so it crash.

My script is this:

import arcpy, os
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/Data/modis_arc/processed/CHL3"
rasterlist = arcpy.ListRasters("*", "TIF")
for raster in rasterlist:
    clt_name = os.path.join("C:/Data/modis_arc/processed/CHL3/reclass2/", raster)
    outReclass1 = Reclassify(raster, "Value", RemapValue([[0,1],[1,1],[5,1],[64,1]]), "NODATA")
    outReclass1.save(clt_name)
  • Please provide the error message you receive when the script crashes. – GeoSharp Oct 8 '15 at 13:41
  • @jamesslc No error message, just arcGIS crash, the program close completely. I have to restart again. I have to say that arcGIS is working ok, I have done other task perfectly. – Jaime Lopez Oct 8 '15 at 15:29
  • It might be helpful to put your code in a try/catch block. See python documentation here or a python wiki here. – GeoSharp Oct 8 '15 at 15:36
  • Wouldn't expect it to cause a crash, but do you check out the sp analyst extension? – jbosq Oct 8 '15 at 19:04
  • Could be naming, remove .tif from name and try with grids. Make sure it does not create illegal name for grid – FelixIP Oct 9 '15 at 4:27
1

You could try using a simple conditional instead of reclassify:

for raster in rasterlist:
    clt_name = os.path.join("C:/Data/modis_arc/processed/CHL3/reclass2/", raster)
    outReclass1 = Con((Raster(raster) == 0) | (Raster(raster) == 1) | (Raster(raster) == 5) | (Raster(raster) == 64), 1)
    outReclass1.save(clt_name)

If raster value is 0, 1, 5, or 64 it will return a value of 1, otherwise it will exclude pixels (no data)

  • use "outReclass1 = Con((Raster(raster) == 0) | (Raster(raster) == 1) | (Raster(raster) == 5) | (Raster(raster) == 64), 1, 0)" if you want to have a binary system (0 = no data) – cartoscience Feb 20 '17 at 18:11
0

Try this:

import arcpy, os
from arcpy import env
env.overwriteoutput=True
from arcpy.sa import *
env.workspace = "C:/rubbish"
aList=[0,1,5,64]
rasterlist = arcpy.ListRasters("*", "TIF")
for raster in rasterlist:
    clt_name = os.path.join("C:/rubbish/output/", raster)
    rr=arcpy.Raster(raster)
    rList=[]
    for n in aList:
        m=Con(rr==n,1,0)
        rList.append (m)
    outCell = CellStatistics(rList, "SUM")
    i=int(arcpy.GetRasterProperties_management(outCell,"MAXIMUM","#")[0])
    if i>0:
        arcpy.AddMessage('%s converted' %clt_name)
        outReclass1=Con(outCell==1,1)
        outReclass1.save(clt_name)
    else:
        arcpy.AddMessage('%s can be saved, but will look weird' %clt_name)

Your guess was correct, if no number in list, it produces invisible raster with massive number, which is actually NODATA value = 2147483647. Thus no worries, remove last condition. I even think that your original solution might work if you convert raster (that is string) into raster using arcpy.Raster(raster)

  • Hi @felixip, First, I try to run your code but it takes so much time...i suppose because my image size; besides, I have to process >500 images, so it is not useful to me. Second, I changed raster by arcpy.Raster(raster) to my original code, but I continues crashing the system. Thanks, I appreciate your effort and ideas. – Jaime Lopez Oct 10 '15 at 15:19
  • 2
    I think you should update your Q with all these complications. – FelixIP Oct 10 '15 at 21:49

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.