2

I'm attempting to run the Buffer Analysis tool with a distance of 3 km over multiple shapefiles at the same time. I was given a folder with different types of files and ran a for loop to create a new list with just the files ending with ".shp" that I have below.

import os
import arcpy
from arcpy import env 
env.workspace = "file_path"
env.overwriteOutput = True
items = os.listdir("file_path")
 newlist = []

for names in items:
    if names.endswith(".shp"):
        newlist.append(final)
print newlist

Thus, this creates my list with just the shapefiles. However, this is where I struggle. I'm not sure how to run the buffer analysis tool over this new list that I've created.

2
  • 1
    Try reviewing Q&As here tagged arcpy for-loop or research for loops at Stack Overflow.
    – PolyGeo
    Commented Oct 4, 2019 at 22:47
  • 1
    I've found the information at this site pretty useful for figuring out batch processing in ArcPy. Might be worth taking a look at.
    – Benjamin
    Commented Oct 5, 2019 at 1:15

1 Answer 1

1

Arcpy has a special method called ListFeatureClasses that will list all the feature classes in the workspace. If the workspace is a folder, then it is likely the feature classes will be shapefiles. You can use the list in a loop. Then apply the buffer analysis. The trick will be getting the outname.

import arcpy
from arcpy import env 
env.workspace = "file_path"
env.overwriteOutput = True
fcs = arcpy.ListFeatureClasses():

for fc in fcs:
    arcpy.Buffer_analysis(fc, OutputName, "100 Feet", "FULL", "ROUND", "LIST", "Distance")

Here is the documentation on buffers: http://desktop.arcgis.com/en/arcmap/10.3/tools/analysis-toolbox/buffer.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.