I have 5 buffers to perform using 5 fields of a shapefile. I try to run it with the following code:
Buffers = ['JF1','JF2','JF3','FF','FB']
env.workspace = "C:\Mydirectory\Myfile.shp"
network = "C:\Mydirectory\Myfile.shp"
out = "C:\Myoutputdirectory\Myfinaldirectory"
for buff in Buffers:
arcpy.Buffer_analysis(network, out, buff,)
But when I do it I receive the following error:
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000725: Output Feature Class: Dataset Myfinaldirectory.shp already exists.
Failed to execute (Buffer).
What is the problem?
asked Apr 22, 2016 at 17:22
-
2Along with @Paul answer, make sure you turn the slashes around in the file paths and remove the extra comma after buff argument in the buffer statement.artwork21– artwork212016年04月22日 17:42:48 +00:00Commented Apr 22, 2016 at 17:42
1 Answer 1
You aren't specifying a name for your output shapefile. arcpy
is treating out
as a file and appending ".shp"
for you. You want a unique name for each output so that it isn't overwritten each loop.
import os
Buffers = ['JF1','JF2','JF3','FF','FB']
# This is a workspace
env.workspace = r"C:\Mydirectory"
# This is present in the workspace
network = "Myfile.shp"
# This is a directory, not a file
out = r"C:\Myoutputdirectory\Myfinaldirectory"
for buff in Buffers:
# results in .\JF1.shp, .\JF2.shp, etc.
arcpy.Buffer_analysis(network, os.path.join(out, buff), buff)
Edit: Fixed pathing per @artwork21 comments. Thanks!
answered Apr 22, 2016 at 17:29
-
Thank you now I do not receive that error anymore. Nevertheless now the code still does not run, and provides me with the following error: arcpy.Buffer_analysis(network, os.path.join(out,buff), buff,) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\analysis.py", line 692, in Buffer raise e ExecuteError: ERROR 000210: Cannot create output C:\MydirectoryJF1 Failed to execute (Buffer). What may be the reason now?Patapunfate– Patapunfate2016年04月24日 09:31:32 +00:00Commented Apr 24, 2016 at 9:31
-
I solved the problem apparently I am not allowed to create folders outside the ArcGIS gdb folder. I simply modified my directory and now it worksPatapunfate– Patapunfate2016年04月25日 10:29:38 +00:00Commented Apr 25, 2016 at 10:29
lang-py