batch reclassify rasters

1765
2
Jump to solution
04-12-2012 09:47 AM
WadeGivens
New Contributor II
I'm trying to batch reclassify a set of rasters in ModelBuilder by assigning an interger from 1-8.  So if raster value is 1-1.5 =1.5-2.5=3, ...... 7.5-8=8

I know I can put these values in a table, but it would be nice to embed it in the model for portability.

Thanks!
0 Kudos
1 Solution

Accepted Solutions
BrianCohen
New Contributor III
Hi

If you want to do it directly with Python, here's an example. Bear in mind that this works on integer rasters, so you will need to modify the remap table function.

# Name: reclassify_example02.py
# Description: Reclassifies the values in a raster.
# Requirements: Spatial Analyst Extension
# Author: ESRI, modified by Brian Cohen

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

# Set environment settings
env.workspace = "N:/South_Coast/Geo_Data/Climate/SDMs/plantsout"
count = 0

# Get list of rasters from workspace
rasterList = arcpy.ListRasters("*", "All")

# sort alphabetically
rasterList.sort()

for inRaster in rasterList:

# set the reclassify field
    reclassField = "Value"

# create the remap value table (here, changing all values to 0 save for 1, which remains the same)
    remap = RemapValue([[0, 0], [1, 1],[2, 0],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0]])

# Check out the ArcGIS Spatial Analyst extension license
    arcpy.CheckOutExtension("Spatial")

# Execute Reclassify
    outReclassify = Reclassify(inRaster, reclassField, remap, "NODATA")

# set the output path
    outpath = "N:/South_Coast/Geo_Data/Climate/SDMs/plantscores/score01/"

# Save the output
    output = os.path.join(outpath, inRaster)
    outReclassify.save(output)

View solution in original post

0 Kudos
2 Replies
BrianCohen
New Contributor III
Hi

If you want to do it directly with Python, here's an example. Bear in mind that this works on integer rasters, so you will need to modify the remap table function.

# Name: reclassify_example02.py
# Description: Reclassifies the values in a raster.
# Requirements: Spatial Analyst Extension
# Author: ESRI, modified by Brian Cohen

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

# Set environment settings
env.workspace = "N:/South_Coast/Geo_Data/Climate/SDMs/plantsout"
count = 0

# Get list of rasters from workspace
rasterList = arcpy.ListRasters("*", "All")

# sort alphabetically
rasterList.sort()

for inRaster in rasterList:

# set the reclassify field
    reclassField = "Value"

# create the remap value table (here, changing all values to 0 save for 1, which remains the same)
    remap = RemapValue([[0, 0], [1, 1],[2, 0],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0]])

# Check out the ArcGIS Spatial Analyst extension license
    arcpy.CheckOutExtension("Spatial")

# Execute Reclassify
    outReclassify = Reclassify(inRaster, reclassField, remap, "NODATA")

# set the output path
    outpath = "N:/South_Coast/Geo_Data/Climate/SDMs/plantscores/score01/"

# Save the output
    output = os.path.join(outpath, inRaster)
    outReclassify.save(output)
0 Kudos
WadeGivens
New Contributor II
That works perfectly.  Now if I could only do this based on unique to each raster, quantile classification....
0 Kudos