How do I reclassify many rasters in ModelBuilder when each raster has its own unique values?

For example, when you create a model in ModelBuilder and you add the Reclassify tool you may want to reclass several rasters with the Iterate Raster tool as an input. However, when you open the Reclass toolbox you choose a value for reclassification and then name it as an output raster. The problem is how can you, when iterating the raster, reclass with several reclassification values for each raster? This is what I am trying to do.

@Michael Miles-Stimson Here is the python I copied and paste here.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Reclassify2006.py
# Created on: 2014-06-23 16:22:40.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Check out any necessary licenses

# Load required toolboxes
arcpy.ImportToolbox("Model Functions")

# Local variables:
Final_NDVI = "E:\\FY2013_projects\\PMC_project\\USGS EarthExplorer\\2006\\Final_NDVI"
v_outFGDB___Value__new = "E:\\FY2013_projects\\PMC_project\\USGS EarthExplorer\\2006\\Vectors\\NDVI_reclassify.gdb"
v_Name_ = "E:\\FY2013_projects\\PMC_project\\USGS EarthExplorer\\2006\\reclassify\\%Name%"
v_Value__new = "E:\\FY2013_projects\\PMC_project\\USGS EarthExplorer\\2006\\Vectors\\NDVI_reclassify.gdb\\%Value%.shp"
Name = "ast_l1b_00302032006175500_20101030104009_12125_ndvi"
v_Value__new__2_ = "E:\\FY2013_projects\\PMC_project\\USGS EarthExplorer\\2006\\Vectors\\NDVI_reclassify.gdb\\%Value%.shp"
ast_l1b_00302032006175500_20101030104009_12125_ndvi_img = "E:\\FY2013_projects\\PMC_project\\USGS EarthExplorer\\2006\\Final_NDVI\\ast_l1b_00302032006175500_20101030104009_12125_ndvi.img"

# Process: Iterate Rasters
arcpy.IterateRasters_mb(Final_NDVI, "a*", "", "NOT_RECURSIVE")

# Process: Reclassify
arcpy.gp.Reclassify_sa(ast_l1b_00302032006175500_20101030104009_12125_ndvi_img, "Value", "-0.17647059261798859 0.022727273404598236 1;0.022727273404598236 0.10313901305198669 2;0.10313901305198669 0.1428571492433548 3;0.1428571492433548 0.16883116960525513 4;0.16883116960525513 0.19117647409439087 5;0.19117647409439087 0.21538461744785309 6;0.21538461744785309 0.24324324727058411 7;0.24324324727058411 0.29870128631591797 8;0.29870128631591797 0.56451612710952759 9", v_Name_, "DATA")

# Process: Parse Path
arcpy.ParsePath_mb(Name, "NAME")

# Process: Raster to Polygon
tempEnvironment0 = arcpy.env.parallelProcessingFactor
arcpy.env.parallelProcessingFactor = "ast_l1b_00302032006175500_20101030104009_12125_ndvi"
arcpy.RasterToPolygon_conversion(v_Name_, v_Value__new, "SIMPLIFY", "VALUE")
arcpy.env.parallelProcessingFactor = tempEnvironment0

# Process: Add Field
arcpy.AddField_management(v_Value__new, "Acres", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
arcpy.CalculateField_management(v_Value__new__2_, "Acres", "[Shape_Area]", "VB", "")
  • 1
    Would you be interested in iterating in python? Jun 23 '14 at 22:15
  • @Michael Miles-Stimson - Sure but I am not familiar with it.
    Jun 23 '14 at 22:16
  • You can export your model (without recursion) into a python script to get an idea of what's going on. Post that and I'll help with the recursion. Jun 23 '14 at 22:18
  • Ok, I have a lot of raster to reclassify so I export it as a python script. This one has a few raster because once I get it right then I will use this script for other to run some more raster.
    Jun 23 '14 at 22:26
  • 1
    I only need to see what's happening with one raster and then know whether you want to do a folder of rasters or a list of rasters. Jun 23 '14 at 22:43

You can actually do this in model builder without python but it is finicky and a bit of a workaround.

  1. create your model with the iterators for the first reclass and make the reclass table a parameter in the model.
  2. right click on your model and set it to batch.
  3. Now you have the reclass table as the parameter.
  4. Use the + button to add the number of reclassses you have (20 different reclasses in this example - add twenty lines with the plus button).
  5. Now in the twenty reclasses boxes on the batch screen load your remap tablesor set the remap in the box (it is kind of like CSV code in this box).

Reclassify is usefull if you have a static look up table. If this is your case, you can use an ascii file (reclassByASCIIFile)with the old and new values and run your model with the iterate raster tool.

If you have a different look up table associated with each raster, then I recommend that you use Python. But if you can define a rule for the reclassification, then you should use map algebra instead (for instance (input - min)/(max-min) + min to change your range)


Besides setting a rule using map algebra as Radouxju suggested, if you have a reclass table for each of the raster you want to process, you could use the model builder variable to call the reclass table ascii file (using reclassByAsciiFile). So in your modelBuilder you would have, at some point, something line %InputRasterName%.asc for your reclass table related to your Input Raster. Of course, this route is not the most straight forward and I'd recommend go the python way as others have said.

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.