nesting for statements?

tpcolson at gmail.com tpcolson at gmail.com
Mon Nov 28 09:27:05 EST 2005


Hi. Thanks for the tip. However, implementing that example, the script
will only generate the second output "file", (or it's overwriting the
first one), so all I get when run is "fileb".

# Import system modules
import sys, string, os, win32com.client

# Create the Geoprocessor object
from win32com.client import Dispatch
gp = Dispatch("esriGeoprocessing.GpDispatch.1")

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

# Iterate 2 thru 4 in increments of 2 for DEF
# Name the "2" dem "outa" and the "4" dem "outb"
sor = 2     # start of range
eor = 4     # end of range

filenames = ['file' + chr((x-sor) + ord('a')) for x in range(sor, eor)]

for x in range(sor, eor):
     Out_Dem = filenames[x - sor]


try:

# Process: Topo to Raster...
    gp.TopoToRaster_sa("C:\\temp\\test.shp Z PointElevation",
                       "C:\\temp\\"+Out_Dem, # Variable for name of
output raster. This should increment name of output based on the for
statement
                       "5", # Output raster cell size: each pixel is 5
feet by 5 feet
                       "2103763.27 813746.12 2111850.32 822518.65",
#extent of raster borders, SPF, NC, NAD83
                       "20", # #Grid Margin
                       "", #Smallest z value to be used in
interpolation (optional)
                       "", #Largest z value to be used in interpolation
(optional)
                       "NO_ENFORCE", #Drainage option
                       "SPOT", #Spot data option
                       "40", #Maximum number of iterations (optional)
                       "", #Roughness penalty (optional)
                       "0" #Discretisation error factor: This should
increment DEF based on the for statement
                       "0", #Vertical standard error (optional)
                       "", #Tolerance 1 (optional)
                       "" #Tolerance 2 (optional)
                       )
except:
    print "ERROR OCCURED"
    print gp.GetMessages()




More information about the Python-list mailing list