Automated Geoprocessing

Discussion created by katze01 on Dec 10, 2011
Latest reply on Dec 14, 2011 by katze01
I'm a python newbie trying to do some georpocessing automation using python with ArcGIS 9.3.

What I want to do is the following:

Read the shapefiles in the input folder, process buffer and clip and name the files automatically.

import sys, os, arcgisscripting
gp = arcgisscripting.create(9.3)
gp.workspace = sys.argv[0]
outws = sys.argv[1]
gp.OverWriteOutput = True
clipFeatures = sys.argv[2]
end = [".shp"]

name = []
x = 0
fcs = gp.ListFeatureClasses()

for fc in fcs:
    name.insert (x, fc.split(".")[0])
    x += 1

x = 0

for fc in fcs:
    outbuff = outws + "/" + name[x] + "_buff" + end [0]
    result = gp.buffer(fc, outbuff, "5000 Meters")
    x += 1

x= 0

for fc in fcs:
    out_Clip = outws + "/" + name[x] + "_clip" + "." + end [0]
    if str(fc) != str(os.path.split(clipFeatures)[1]):
        gp.Clip_analysis(clipFeatures, result, out_Clip)

I get error massages like

"the geoprocessor object is not iterable" etc.

But when I put the code
for fc in fcs:
    name.insert (x, fc.split(".")[0])
    x += 1

on its own into the interactive window (of course, first I create the geoprocessing object, workspace etc.), it works and prints the list
>>> [u'A.shp', u'B.shp', u'C.shp', u'Clip.shp', u'D.shp']

without errors.

Any ideas how to improve my newbie code and get rid of the errors?



Still working on it, for now at least the buffering it working, still have problems with passing on the results to the Clip tool.