PSU-CSAR / awdb-retrieve

Automation script to download station metadata records from the NRCS Air Water Database.
1 stars 1 forks source link

Script is failing when trying to update the huc2 field to the temporary feature class #14

Closed lbross closed 3 months ago

lbross commented 3 months ago

ERROR 000539: Invalid field L0active_stations_FCST.huc2 Failed to execute (CalculateField).

Traceback (most recent call last): File "C:\workspace\awdb-retrieve\get_AWDB_stations_3.py", line 812, in update_forecast_point_ws CalculateField_management(joined_table, f"{FCST_Active_Temp}.{HUC2}", expression, "PYTHON3", codeblock) File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 6187, in CalculateField raise e File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 6184, in CalculateField retval = convertArcObjectToPythonObject(gp.CalculateField_management(gp_fixargs((in_table, field, expression, expression_type, code_block, field_type, enforce_domains), True))) File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing_base.py", line 512, in return lambda args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 000539: Invalid field L0active_stations_FCST.huc2 Failed to execute (CalculateField).

lbross commented 3 months ago

Something the AddField loop was failing when trying to add the WINTER_START_MONTH, WINTER_END_MONTH, HUC2, and BAGIS_NOTE fields. Added code to check for existence of field before trying to add it. This fixed the problem.

lbross commented 3 months ago

I thought this was fixed but it still wasn't working. Found that I was using the wrong field name when trying to access fields in the joined layer. Also the code that added the new fields to the temporary feature class was inefficient and needed to be cleaned up. About to publish to basins ...