I am a newbie of python teaching myself using the arcpymanual. I am running a Reclassify script on slope grids. It works fine for the first loop then I get an error message for the remap line. I cannot figure out what the problem is because I copied the syntax from the arcpy manual. Is it due to loop syntax?
Runtime error Traceback (most recent call last): File "", line 21, in TypeError: 'RemapRange' object is not callable
SCRIPT:
import arcpy
from arcpy import env
from arcpy.sa import *
# Set the current workspace
arcpy.env.workspace = r"C:\workspace\rsn\pippi"
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
# Process: Reclassify
rasters = arcpy.ListRasters("s_*", "GRID")
for raster in rasters:
print(raster)
outRaster = r"C:\workspace\rsn\pippi\re_" + raster
print(outRaster)
RemapRange = RemapRange([[0, 15, 0], [15, 30, 1], [30, 90, 2]])
outReclassRr = Reclassify(raster, "Value", RemapRange, "DATA")
print outReclassRr
outReclassRr.save(outRaster)
Can anyone give any suggestions?
1 Answer 1
Your variable RemapRange is named the same as the object RemapRange which is not good coding practice. Try renaming that statement to something like:
myRemapRange = RemapRange([[0, 15, 0], [15, 30, 1], [30, 90, 2]])
I would also recommend to place that statement before the for loop since it is static variable and does not need re-created for each image.
rasters = arcpy.ListRasters("s_*", "GRID")
myRemapRange = RemapRange([[0, 15, 0], [15, 30, 1], [30, 90, 2]])
for raster in rasters:
# continue on with logic