listRasters flowaccumulation ArcGIS9.3.1

315
2
08-16-2011 03:55 AM
EstherJensen
New Contributor III
Hello,
I am new to Python. When I run my script from toolbox nothing happens. But when I step through it in PythonWin I get the error: AttributeError: 'list' object has no attribute 'next'

My code looks like this:

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

# Check out any necessary licenses
gp.CheckOutExtension("spatial")

#input workspace
inWS = gp.GetParameterAsText(0)
#output folder
outFolder = gp.GetParameterAsText(1)
#input flowdir
inFD = gp.GetParameterAsText(2)

#Set the workspace where the output folder is
gp.workspace = inWS
gp.addmessage("Input workspace")
gp.addmessage(inWS)
gp.addmessage("Output workspace")
gp.addmessage(outFolder)
gp.addmessage("flow direction")
gp.addmessage(inFD)

#Python will overwrite exsisting outputfiles
gp.overwriteoutput = 1

# Load required toolboxes...
gp.AddToolbox("C:\Program Files (x86)\ArcGIS\ArcToolBox\Toolboxes/Spatial Analyst Tools.tbx")


#Get a list of the tables in the input folder
rasList = gp.ListRasters("*", "GRID")

#Loop through the list of rasters
ras = rasList.next()

while ras:

    outRaster = outFolder + "/" + ras
    # Process: Flow Accumulation...
    print ras
    gp.FlowAccumulation_sa(inFD, outRaster, ras, "INTEGER")
    # Move on to next grid in the list 
    ras = rasList.next()

Regards,
Esther
Tags (2)
0 Kudos
2 Replies
BruceNielsen
Occasional Contributor III
If your call to ListRasters is truly returning a list, then you'll want to use a for loop instead of a while. I'd also change the outRaster assignment to make a little more robust:
for ras in rasList:
  outRaster = os.path.join(outFolder,ras)
  # Process: Flow Accumulation...
  print ras
  gp.FlowAccumulation_sa(inFD, outRaster, ras, "INTEGER")
  # Move on to next grid in the list 
There will be no further need for either 'ras = rasList.next()' statement.
0 Kudos
EstherJensen
New Contributor III
it seems to work better but it am still getting errors: Failed to execute. Parameters are not valid.
ERROR 000876: Output accumulation raster: V:\python\output\Q2.asc's extension is invalid for the output raster format.

I have tried to use both ascii rasters and ESRI GRID.
0 Kudos