Hi everyone! I'm trying run this code in arcpy 2.7 for ArcMap 10.8, but appears a error when write the output files. This code intersects multiple shapefiles from a folders and subfolders and calculate the area exporting the excel from this files intersected.I have another version this code for Arcgis Pro in arcpy 3.7 and runs with no problem. The error is:
Traceback (most recent call last):
File "C:\Users\Brubisgeo\Downloads\intersect.py", line 20, in <module>
arcpy.Intersect_analysis([fc, inter], newfile, "ALL", "", "INPUT")
File "c:\program files (x86)\arcgis\desktop10.8\arcpy\arcpy\analysis.py", line 334, in Intersect
raise e
ExecuteError: ERROR 000210: Cannot create output C:\Users\Brubisgeo\Downloads\teste_1\intersected_C:\Users\Brubisgeo\Downloads\clipar tudo\BR_Municipios_2021\BR_Municipios_2021.shp
Failed to execute (Intersect).
How can i fix this?
The code:
import os
import arcpy
inter = arcpy.GetParameterAsText(0)
input_folder = arcpy.GetParameterAsText(1)
output_folder = arcpy.GetParameterAsText(2)
arcpy.env.overwriteOutput=True
arcpy.env.workspace = input_folder
list_fcs = arcpy.ListFeatureClasses()
for root, directory, files in os.walk(input_folder):
for fc in files:
if fc.endswith('.shp'):
rename_shp = "intersectedo_{}".format(fc)
rename_excel = "calculado_{}.xls".format(os.path.splitext(fc)[0])
newfile = os.path.join(output_folder,rename_shp)
newtable = os.path.join(output_folder,rename_excel)
arcpy.Intersect_analysis([fc, inter],newfile,"","","")
desc = arcpy.Describe(fc)
geometry = desc.shapeType
if geometry == 'Polygon':
fieldName = "NEW_AREA"
expr ='!shape.area@hectares!'
arcpy.management.AddField(newfile,fieldName,"DOUBLE")
arcpy.CalculateField_management(newfile,fieldName,expr,'PYTHON')
arcpy.TableToExcel_conversion(newfile,newtable)