I'm trying to create a custom Single Output Map Algebra script so that I can have my user input values to run using python. My python code is:
# ---------------------------------------------------------------------------
# rad226_67.py
# Created on: Thu Nov 24 2011 11:13:19 AM
# (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------
# Import system modules
import sys, string, os, arcgisscripting, glob
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Check out any necessary licenses
gp.CheckOutExtension("spatial")
# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")
# Local variables...
imdir = 'E:\\223_67' #
os.chdir(imdir) #
path = '*.tif' #
lista_in = glob.glob(path) #
lista_out = ["E:\\223_67\\rad_223_67_B1.tif", "E:\\223_67\\rad_223_67_B2.tif", "E:\\223_67\\rad_223_67_B3.tif",]
#v226_67_rad_tif = "E:\\223_67_rad.tif"
nimg = [0,1,3]
for i in nimg:
print i
img_in = lista_in
print img_in
img_out = lista_out
print img_out
# Process: Single Output Map Algebra...
gp.SingleOutputMapAlgebra_sa("- 1.52 + "+ img_in + " * ( 169 + 1.52 ) / 255", img_out, "")
When I ran for one image no errors, but for more I´m currently getting this error:
0
LANDSAT_5_TM_20100617_223_067_L2_BAND1.tif
E:\223_67\rad_223_67_B1.tif
1
LANDSAT_5_TM_20100617_223_067_L2_BAND2.tif
E:\223_67\rad_223_67_B2.tif
Traceback (most recent call last):
File "C:\Work2011\INPE\landsat\rad226_67.py", line 37, in <module>
gp.SingleOutputMapAlgebra_sa("- 1.52 + "+ img_in + " * ( 169 + 1.52 ) / 255", img_out, "")
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000865: Map Algebra expression: LANDSAT_5_TM_20100617_223_067_L2_BAND2.tif does not exist.
Failed to execute (SingleOutputMapAlgebra).
Any help on why this is happening would be much appreciated!
Thanks