How does someone write a python script on arcpy.Buffer_analysis site package to buffer multiple shapefiles (e.g. roads.shp, schools.shp) with multiple distances (e.g. 500ft, 1000ft, 1500ft, 2000ft, 2500ft) and allowing them to have individual output file names?

New to python scripting.



inputFeature = "roads.shp"

outputFeature = "roads_500ft"

bufferdist = '500 Feet'

arcpy.Buffer_analysis(inputFeature,outputFeature,bufferdist, "","", "ALL")
import arcpy

arcpy.env.workspace = "path"  # folder with all the shapefiles
buff_distances = ['500 feet', '1000 feet', '1500 feet', '2000 feet']

folder = "path2"  # folder to store output

for file in arcpy.ListFeatureClasses():
    for dist in buff_distances:
        out_file = '{}_{}ft.shp'.format(file[:-4], dist[:-5])
        arcpy.Buffer_analyisis(file, "{}/{}".format(folder, out_file), bufferdist=dist, "", "", "ALL")

you could put your input features and buffer distances into lists and iterate through a couple of for loops

import arcpy  
import os
outputPath = set output path
inputFCList = ['FeatureClass1','FeatureClass2','FeatureClass3']
for inputFC in inputFCList:
    desc = arcpy.Describe(inputFC)
    bufferList = [500, 1000, 1500]
    for buffer in bufferList:        

Your output will be saved in your set output path and will take the name of the feature class + "_" + the buffer distance. Also be sure to have your map units set correctly, if your map units are in feet then the buffer will be 500 feet, 1000 feet, 1500 feet. Same thing with miles if your map units are set to miles, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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