Reclassify script using Remap data type

3170
4
11-09-2012 03:25 AM
stevenwilliams1
New Contributor
Guys,

I am having trouble feeding data through to Remap in the script below.  I know im making a mistake somewhere but l cant work out what it is.  I can't get the reclass_field to populate with the raster 'Value'.  Basically l want to reproduce the spatial analyst reclassify tool and then add some more weighted functions afterwards, but im getting stuck from the off.  Please can someone help me out here?

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *


# Get Parameters
infc      = arcpy.GetParameterAsText(0)
reclass_field =  arcpy.GetParameterAsText(1)
reMap = arcpy.GetParameterAsText(1)
outfc     = arcpy.GetParameterAsText(2)

# Local Parameters

recl_data  = "DATA"

# Reclassify
outRecl = arcpy.sa.Reclassify(infc, reclass_field, reMap, recl_data)
outRecl.save(outfc)

Steve
Tags (2)
0 Kudos
4 Replies
RaphaelR
Occasional Contributor II
a similar problem is discussed in this topic:
http://forums.arcgis.com/threads/49918-Reclassify-GUI-form-not-active-in-Python-script?highlight=rem...

at 10.0 i haven´t managed to get the remap to work in a script so far.
0 Kudos
stevenwilliams1
New Contributor
Rafaelr, thanks for your reply ive seen this discussion but l am trying to find the answer as to why you cannot populate the remap tool with the input rasters classification as you mentioned in this discussion.  The tool only seems to allow you to map your own classification as the classify button is greyed out.  The Reclassify tool works fine why cant this be replecated using arcpy, someone in ESRI please answer this, why have a tool which doesnt work?

Steve
0 Kudos
Tom-PierreFrappe-Seneclauze
New Contributor
Gosh that is so frustrating!
I've just spent hours trying to get my first python code to actually run a reclassify, trying every possible permutation. I'm not using the GUI, just pure python -- but no luck.

Is it really that the function doesn't work? ESRI, please respond, that is the least you can do.

Am pasting code here in case is useful; as indicated, I have tried both the RECLASSIFY function in sa and the RECLASSIFY_SA in gp; neither work.

Am happy to provide the mdx and raster files if useful.


mxdname = 'Kaag EOSD map.mxd'                                                
gdbpath = "C:\\GIS DATA\\NWT\\2012-01 Ka'a'gee tu\\2.processed\\Kaag.gdb\\"  # path to where this mxd file is stored
eosd_rs =  'EOSD_085CFv2'                                                     # name of raster file to reclassify (ground surface data in our case)

#-> Local variables: outputs
outputfolder = gdbpath 
corename = 'Kaag'                                               # root prefix identifying the project (for naming convention)
os.chdir(gdbpath)                                               # set python current working directory to current geodatabase path
suffix= 'temp' 
out_rs_name = gdbpath+corename+suffix+'_rs'                          # name of the raster to be generated by reclassification
  
## Reclassify
if 1:   # This method is based on help file: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z000000sr000000.htm
        remap = arcpy.sa.RemapValue([ \
        [0, 0.00], \
       [12, 0.00], \
       [20, 5.01], \
       [30, 0.00], \
       [32, 0.00], \
       [33, 0.00], \
       [40, 2.40], \
       [51, 656.07], \
       [52, 656.07], \
       [81, 9163.08], \
       [82, 9163.08], \
       [83, 9163.08], \
       [100, 656.07], \
       [211, 1534.28], \
       [212, 1151.31], \
       [213, 768.34], \
       [221, 1534.28], \
       [222, 1151.31], \
       [223, 768.34], \
       [231, 1534.28], \
       [232, 1151.31], \
       [233, 768.34]]) 
        out_rs=arcpy.sa.Reclassify(eosd_rs, "Value", remap, "NODATA")
        out_rs.save(out_rs_name)
        print out_rs.maximum
              
elif 0: # this is the method that came out of the model builder output
        remap="0  0.00;  \
        12  0.00;  \
        20  5.01;  \
        30  0.00;  \
        32  0.00;  \
        33  0.00;  \
        40  2.40;  \
        51  656.07;  \
        52  656.07;  \
        81  9163.08;  \
        82  9163.08;  \
        83  9163.08;  \
        100  656.07;  \
        211  1534.28;  \
        212  1151.31;  \
        213  768.34;  \
        221  1534.28;  \
        222  1151.31;  \
        223  768.34;  \
        231  1534.28;  \
        232  1151.31;  \
        233  768.34  "

        arcpy.gp.Reclassify_sa(eosd_rs, "Value", remap,out_rs_name , "NODATA")
0 Kudos
curtvprice
MVP Esteemed Contributor

I have usually only used reclassify to reclassify one set of integers to another.

Seems to me a another approach to try would be to try the Lookup() tool instead.

(Logging an incident request with support may be a good idea too!)

For example (untested code - ymmv)

remap = \
[0, 0.00], \
[12, 0.00], \
(...)
[232, 1151.31], \
[233, 768.34]] 
rmDict = dict(zip(i[0] for i in remap],[j[1] for j in remap]))
arcpy.AddField("myrast","REMAP","DOUBLE")
Rows = arcpy.UpdateCursor("myrast")
for Row in Rows:
    val = rmDict[int(Row.VALUE)]   
    Row.REMAP = val
del Row, Rows
from arcpy.sa import *
outRast = Lookup("myrast","REMAP")
outRast.save("rmrast")
0 Kudos