AnsweredAssumed Answered

Raster Calculator within loop

Question asked by workshop1 on Nov 26, 2010
Latest reply on Nov 26, 2010 by workshop1
Hi guys,
I want to use raster calculator with loop to consider many raters. however i got the following error:
[HTML]
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000989: Python syntax error: Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 1)
Failed to execute (RasterCalculator).
[/HTML]

any help would appreciate

Python script is:

import sys, string, os, arcgisscripting, math, arcpy
gp = arcgisscripting.create()
gp.OverWriteOutput = 1
gp.CheckOutExtension("spatial")
gp.AddToolbox("C:/Program Files/ArcGIS/Desktop10.0/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")

gp.workspace = "D:/Rc_FPAR_test/FPAR1000"

out_workspace = "D:/Rc_FPAR_test/FPAR250"
# Get a list of grids in the workspace.
rasters = gp.ListRasters("","TIF")

raster = rasters.next()
while raster:
    print raster
    raster = rasters.next()
rasters.reset()
raster = rasters.next()

print gp.GetMessages()

while raster:
    # Set local variables
    InRaster = raster
    # Set the outputname for each output to be the same as the input.
    OutRaster = out_workspace + "/" + raster
    # Check out Spatial Analyst extension license
    gp.CheckOutExtension("Spatial")
    arcpy.gp.RasterCalculator_sa("0.5913 *" + InRaster + " + 0.3896", OutRaster)
    
    print raster
    raster = rasters.next()
    # If an error occurred while running a tool, then print the messages.
    print gp.GetMessages()

Outcomes