I need to calculate the shape area (and possible the perimiter) of polygons for over 300 files. I tried to use a Python code but I am not very familiar with Python so when it returns an error I do not know where the problem is. My Python code looks like this:
import arcpy
from arcpy import env
import os
import csv
outputFilePath = 'outputPath'
sourceFolderPath = 'inputPath'
for root, dirs, files in arcpy.da.Walk(sourceFolderPath):
for name in files:
if name[-4:] == '.shp':
arcpy.env.workspace = os.path.join(root, name)
arcpy.AddField_management(name[:-4], "Shape_area", "DOUBLE")
arcpy.CalculateField_management(name[:-4], outputFilePath + '/' + name[:-4], "Shape_area", "PYTHON_9.3")
I received this error message:
Traceback (most recent call last):
File "<string>", line 15, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 3290, in CalculateField
raise e
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 3287, in CalculateField
retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block), True)))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
Any suggestions?
[name[:-4]]toname[:-4], thanks, good point. Unfortunately I still get error. A new one saying thatFile "<string>", line 15, in <module>, andParameters are not valid.– Malna Mar 04 '20 at 08:39