I’m using a while statement to count down from x until it = y. Each loop decreases x by 1. This variable (among other variables) is passed into a geoprocessing tool’s expression variable as a string. The string exactly mimics a user specified expression. Alas the ArcPy .gp does not accept my identical variable as an expression.
How does one take a text string, and pass it off as a text expression?
####### Raster values to separate rasters
import arcpy
arcpy.CheckOutExtension("spatial")
######## Script arguments
FolderLocation = "C:\\Data\\Testing\\"
InRaster = "C:\\Data\\ basin00_dem"
TopVal = 236
BotVal = 127
Range = TopVal-BotVal
print "There are: "+ str(Range) +" values to iterate"
print " "
SingleValue = "s1_"
MegaCount = TopVal
while (MegaCount) > BotVal:
MegaCount = MegaCount-1
## Reclass Single Values
SingleValueName = SingleValue + str(MegaCount) +".tif"
SingleValueNamePath = FolderLocation + SingleValueName
RC1 = "\"" + str(BotVal) +" "
RC2 = MegaCount -1
NODATA = " NODATA;"
RC3 = str(MegaCount) +" "
RC4 = str(TopVal)+ " "
Val = "1 " + "\""
Qu = "\""
Equ = str(RC1) +str(RC2) + NODATA + str(RC3) + str(RC4) + str(Val) +str(Qu)
Range = Range -1
print "Number: " + str(Range) + " Equ: " +str(Equ)
arcpy.gp.Reclassify_sa(InRaster, "Value", Equ , SingleValueNamePath, "NODATA")
# WORKING .GP
# arcpy.gp.Reclassify_sa(InRaster, "Value", "127 233 NODATA;234 236 1", SingleValueNamePath, "NODATA")
# Example print of Equ: "127 129 NODATA;130 236 1"