I'm trying to run a script in arcpy and appears the error 000725 "output folder: Dataset C:.. already exists.
The script objective is to clip all shapefiles from a folder by a buffer layer. If the shapefiles clipped are polygons, area is calculated. And I'm trying to export all the Excel tables from these shapefiles with a column called ("NEW_AREA"). I used the arcpy.env.overwriteOutput=True
to fix the error but doesn't work. What am I doing wrong?
My script:
import arcpy
pol = arcpy.GetParameterAsText(0)
buf = arcpy.GetParameterAsText(1)
output_buf = arcpy.GetParameterAsText(2)
input_folder = arcpy.GetParameterAsText(3)
output_folder = arcpy.GetParameterAsText(4)
arcpy.env.workspace = input_folder
arcpy.env.overwriteOutput=True
list_fc = arcpy.ListFeatureClasses()
fc = os.listdir(input_folder)
clip_features = arcpy.Buffer_analysis(pol,output_buf,buf)
def CLIP(input_folder, output_folder, clip_features):
for file in fc:
for i in fc:
if i.endswith(".shp"):
file = os.path.join(input_folder,i)
rename_shp = "clipped_%s" % (i)
rename_excel = "calculated%s" % (i)
newfile = os.path.join(output_folder,rename_shp)
newtable = os.path.join(output_folder,rename_excel)
desc = arcpy.Describe(file)
geometry = desc.shapeType
if geometry == 'Polygon':
fieldName = "NEW_AREA"
expr ='!shape.area@squaremeters!'
arcpy.Clip_analysis(file, clip_features, newfile, "") and arcpy.management.AddField(newfile,"NEW_AREA","DOUBLE") and arcpy.CalculateField_management(newfile,fieldName,expr,'PYTHON') and arcpy.TableToExcel_conversion(newfile,newtable,"NEW_AREA")
else:
arcpy.Clip_analysis(file, clip_features, newfile, "")
CLIP(input_folder, output_folder, clip_features)
.dbf
) file of a shapefile should be kept well clear of Excel, so you don't accidentally corrupt it.fc
which is almost certainly not necessary; The use ofand
after the Clip directive is not best practice, and probably doesn't do what you think it does (can you explain why you're using it?). Comment out all thearcpy
code and see if you can make the Python follow your expected flow of control. Then start coding the geoprocessing.