Select to view content in your preferred language

batch buffer tool error

727
1
06-01-2010 09:53 AM
NatashaJurko
Occasional Contributor
Hello,

I am having problems getting the "BatchBuffer.py" script from the esri script site.  I have altered it a little to fit the system here (working with 9.2).  And I am new to the world of python so maybe I am missing something obvious.  I have followed other posts advice in putting all my input files into geodatabase and not running the script from the Toolbox.
The error message that keeps popping up that I haven't managed to solve is:

Traceback (most recent call last):
  File "W:\NJurko\MontrealLake\testing_ground\BatchBuffer.py", line 46, in ?
    gp.Buffer_analysis(fc, outFeatureClass, bufferSize_param, lineSide, lineEndType, dissolveOption)
RuntimeError:
Error occurred during execution


This is the script I am using:

#Import standard library modules
import sys
import os
import arcgisscripting
#Create the geoprocessor object.
gp = arcgisscripting.create()

#Create a system argument variable the input feature class.
ws = "W:\\NJurko\\MontrealLake\\testing_ground\\mtltest.gdb"
gp.workspace = ws

#Create a sysargv for the output workspace.
outWorkspace = "W:\\NJurko\\MontrealLake\\testing_ground\\ouputs\\"
gp.toolbox = "analysis"
#Create a sysargv for the type of features to be buffered.


#Create sysargv for the buffer tool parameters.
bufferSize = "10"
lineSide = "FULL"
lineEndType = "ROUND"
dissolveOption = "ALL"
dissolveField = "#"
#get a list of the feature classes of type LINE in the input folder.
fcs = gp.ListFeatureClasses()

#Loop through the list of feature classes.
fcs.reset()
fc = fcs.Next()

while fc:
#Generate output path and filename.  The last four characters (".shp") are removed from 'fc' so the new filepath can be generated correctly.
#New file names are [buffered filename]_buff.shp; e.g., "roads_buff.shp"
outFeatureClass = outWorkspace + "\" + fc[:-4]" + "_buff.shp"

#Format the inputed buffer distance so it can be used in the buffer tool.
bufferSize_param = bufferSize + ".000000 meters"

#Buffer each feature class in the list.
gp.Buffer_analysis(fc, outFeatureClass, bufferSize_param, lineSide, lineEndType, dissolveOption)

#Get the next feature class in the list.
fc = fcs.Next()

print gp.GetMessages (1)


Thanks for the help!

NJurko
0 Kudos
1 Reply
NatashaJurko
Occasional Contributor
I figured it out.  Started from scratch this morning.
Here it is for anyone who's interested:

#Import standard library modules
import arcgisscripting, sys, os

#Create the Geoprocessor object
GP = arcgisscripting.create()

#Set the input workspace
GP.workspace = "PathName"

#Set the output workspace
outWorkspace = "PathName"

#INPUTS FOR BUFFER PARAMETERS
bufferDistance = "2 kilometers"
lineSide = "#"
lineEnd = "#"
dissolveOp = "ALL"
dissolveField = "#"

try:
        #Make sure the indents are in the right place!
        #Get a list of the featureclasses in the input folder
        fcs = GP.ListFeatureClasses()

        #Loop through the list of feature classes
        fcs.Reset()
        fc = fcs.Next()

           while fc:

               #Validate the new feature class name for the output workspace.
               outFeatureClass = outWorkspace + "/" + GP.ValidateTableName(fc, outWorkspace)

              #Clip each feature class in the list with the clip feature class.

              GP.buffer_analysis(fc, outFeatureClass, bufferDistance, lineSide, lineEnd, dissolveOp, dissolveField)

              #Move to the next fc in the list.
               fc = fcs.Next()

except:
    print GP.GetMessages(2)



Hope this helps someone in the future!

NJurko
0 Kudos