nesting for statements?

tpcolson at gmail.com tpcolson at gmail.com
Sun Nov 27 12:58:34 EST 2005


I'm not what you'd call a "programmer" of any sort, so perhaps this
question may seem arcane and result in a plethora of "you idiot"
threads, but here goes:

ArcGIS 9.1 has a neat interface with python (2.1-2.4), allowing me to
do all sorts of spatial operations within python, namely, repetitive
functions.


In the below code, I'm trying to iterate thru multiple values of the
variable "Discretisation error factor" using a for statement that
temporarily populates "Disc", which is used as input in "Discretisation
error factor" in the gp.TopoToRaster._sa function.


For each iteration of "Discretisation error factor", I'm trying to name
the output file "outa", "outb", "out...."

Not quite sure how to implement that. There are lots of examples on
nested for loops out there, but nothing on combing that with a output
file naming sheme.

The gp.TopoToRaster_sa function by itself without all the for
statements works fine.

Appreciate any help on this, other wise I have to manually  interpolate
hundreds of LiDAR point clouds, each, 10 times for diff. values of DEF.



# TopoToRaster_sample.py
# Description: Interpolate a series of point features onto a
rectangular raster using TopoToRaster
# Requirements: None
# Author: ESRI
# Date: 12\\01\\03

# 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"
for x in range(2,4):
    Disc = int(x)
    names = ["a","b"]
    for y in names:
            Out_Dem = "out"+y


try:

# Process: Topo to Raster...
    gp.TopoToRaster_sa("C:\\temp\\falls_lidar.shp Z PointElevation",
                       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)
                       Disc, #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