I have a script which reads a geodatabase table and calculate two fields based on existing fields.
This is my code:
import arcpy
from arcpy import env
#overwrite output
arcpy.env.overwriteOutput = True
#Linear reference
def locateFeatures(fc,rts,tbl):
arcpy.LocateFeaturesAlongRoutes_lr(fc, rts, 'RID', '0.1 Meters', tbl,
'RID LINE FMEASN TMEASN')
#add field Diff MEAS
def addFieldDif(tbl):
arcpy.AddField_management(tbl,'DifFMEAS', 'DOUBLE')
arcpy.AddField_management(tbl,'DifTMEAS', 'DOUBLE')
#calculate Diff MEAS
def calFieldDifMeas(fc):
fdList = ['FMEASN','TMEASN','FMEAS','TMEAS','DifFMEAS','DifTMEAS']
with arcpy.da.UpdateCursor(fc,fdList) as cursor:
for row in cursor:
row[4] = abs(row[0] - row[2])
row[5] = abs(row[1] - row[3])
cursor.UpdateRow(row)
fc = r'C:\Users\Gary\Documents\ArcGIS\Default.gdb\PplProt'
rts = r'C:\Users\Gary\Documents\ArcGIS\Default.gdb\PplRoute'
tbl = r'C:\Users\Gary\Documents\ArcGIS\Default.gdb\Locate_MEAS'
locateFeatures(fc,rts,tbl)
addFieldDif(tbl)
calFieldDifMeas(fc)
print'done!!'
When I run the script I get the error:
Traceback (most recent call last):
File ", line 31, in
File "", line 21, in calFieldDifMeas
RuntimeError: A column was specified that does not exist.
Maybe this is a very silly error but I've started learning Python recently and I cannot find a fix anywhere. Can anybody give me a hint of what might be causing the error?
Best Answer
The error
RuntimeError: A column was specified that does not exist.
usually comes from the cursor when you supply in the list of input fields a field that does not exist.There are some things you can do for troubleshooting:
da.UpdateCursor
usingarcpy.ListFields()
:Code:
This should be done before creating a cursor. You should get
True
for all fields.fc
refers to.