Hi I'm trying to implement a "nested" conditional statement using the singleoutmapalgebra tool via Python. Since there are multiple nested con statements I've been trying to use concatentation, however I'm having trouble with the syntax. Any advice would be greatly appreciated.
Here's a simplified portion of the script, which still yields the following error: "TypeError: cannot concatenate 'str' and 'int' objects"
import sys, string, os, arcgisscripting
gp = arcgisscripting.create()
gp.overwriteoutput = 1
gp.CheckOutExtension("spatial")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
inFolder = r"F:\input"
gp.workspace = inFolder
#List Rasters..
rasters = gp.ListRasters("*int")
rasters.Reset()
raster = rasters.Next()
while raster:
print raster
output_location = r"Z:\out"
output_folder = str(raster)
OutPath = output_location + "\\" + output_folder
print OutPath
Output = OutPath + "\\" + "_Out"
gp.CreateFolder_management(output_location, output_folder)
gp.refreshcatalog(output_location)
count = gp.GetRasterProperties_management(raster, "UNIQUEVALUECOUNT")
print count
ID99 = int ( (count * 99 /100 + 0.5))
print ID99
ID95 = int ( (count * 95 /100 + 0.5))
print ID95
ID90 = int ( (count * 90 /100 + 0.5))
print ID90
ID85 = int ( (count * 85 /100 + 0.5))
print ID85
ID80 = int ( (count * 80 /100 + 0.5))
print ID80
rows = gp.searchcursor(raster)
row = rows.Next()
while row:
value = row.getvalue("ID")
if value == ID99:
print "Value99..."
value99 = row.getvalue("VALUE")
print value99
elif value == ID95:
print "Value95..."
value95 = row.getvalue("VALUE")
print value95
elif value == ID90:
print "Value90..."
value90 = row.getvalue("VALUE")
print value90
elif value == ID85:
print "Value85..."
value85 = row.getvalue("VALUE")
print value85
elif value == ID80:
print "Value80..."
value80 = row.getvalue("VALUE")
print value80
row = rows.Next()
gp.SingleOutputMapAlgebra_sa("CON( " + raster + " >= " + value99 + ", 99, 0)", Output)
print "Output"
raster = rasters.Next()
print "done"
Many thanks for your help.
James