5

I'm trying to buffer multiples files at once using ArcGIS. My code looks correct until the last line where it returns error related to buffer tool. I've used this code.

import arcpy
import os
from arcpy import env
path = "G:\\Python\\Arcgis\\Materials"
env.workspace = "C:\\Users\\XYZ\\Documents\\ArcGIS\\Default.gdb"
arcpy.env.overwriteOutput = True
inputlist = []
shapelist = os.listdir(path)
shapelist = [x for x in shapelist if x.endswith(".shp")]
for shape in shapelist:
    print(shape)
    inputlist.append(shape)
output = "G:\\Python\\Arcgis\\Buffer"
distanceField = "100 Feet"
arcpy.Buffer_analysis(inputlist, output, distanceField)

The error obtained while using ArcGIS pro be seen here

Also, I've tried it in ArcGIS Desktop as well as ArcGIS Pro. The files are projected. The error while using ArcGIS Desktop is as follows:

PS G:\Python\Arcgis> & c:/Python27/ArcGIS10.4/python.exe g:/Python/Arcgis/buffer_standalone.py
area1.shp
area2.shp
area3.shp
Traceback (most recent call last):
  File "g:/Python/Arcgis/buffer_standalone.py", line 15, in <module>
    arcpy.Buffer_analysis(inputlist, output, distanceField)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\analysis.py", line 692, in Buffer
    raise e
RuntimeError: Object: Error in executing tool
2
  • 2
    In most geoprocessing tools where a "list" is expected, the parameter is actually a string with semicolon delimiters. Try using ';'.join(inputlist).
    – Vince
    Apr 25, 2021 at 14:05
  • Hi, unfornutely it doesn't seem to work out. I tried Buffer_analysis(";".join(inputlist), output, distanceField) After trying,error still persists arcpy.Buffer_analysis(";".join(inputlist), output, distanceField) File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\analysis.py", line 692, in Buffer raise e arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset area1.shp;area2.shp;area3.shp does not exist or is not supported Failed to execute (Buffer). I tried printing data type of inputlist, it shows list.
    – bhushan11
    Apr 25, 2021 at 14:39

1 Answer 1

7

You get the error because you pass a list for the first parameter. Instead, use the tool in for loop with path of the file.

import arcpy
import os

arcpy.env.overwriteOutput = True
input_path =  "G:\\Python\\Arcgis\\Materials\\"
output_path = "G:\\Python\\Arcgis\\Buffer\\"

shapelist = os.listdir(input_path)
shapelist = [x for x in shapelist if x.endswith(".shp")]

distanceField = "100 Feet"

for shape in shapelist:
    print(shape)
    in_file_name = input_path + shape
    print(in_file_name)
    out_file_name = output_path + shape[:-4] + "_buffer.shp"
    print(out_file_name)

    arcpy.Buffer_analysis(in_file_name, out_file_name, distanceField)
0

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.