使用Arcmap 10.1或更高版本的Arcpy.da.UpdateCursor SQL错误

时间:2014-04-07 15:16:49

标签: arcpy

我正在尝试更新列“DR1cond”(这意味着驱动程序1条件)。

目前,司机条件表示“饮酒”或“睡觉”或“其他许多条件”。我想更新get row所以“喝”= 1或“睡觉”= 2。

但是我收到了一个sql错误:到目前为止我的内容是:

#Update Cursor to replace current string data with numbers

import arcpy

arcpy.env.workspace = r'C:\Crash\Fatal03-12.shp'

updateFC = 'DR1cond'

print 'Creating update cursor for',updateFC,' in ',arcpy.env.workspace

updateRows = arcpy.da.UpdateCursor(updateFC,["DR1cond"])

#Loop through each Driver conidition and determine replace

print 'Updating DR1cond class field for get row..."

for row in updateRows: 
    ShapeIndex = row[0]
    if(shapeIndex = 'Drinking'):
      DR1cond = "1"
    elif(shapeIndex = 'fatigue' or 'Asleep'):
      DR1cond = "2"
    elif(shapeIndex = 'Normal'):
      DR1cond = "3"
    elif(shapeIndex = 'Drug use'):
      DR1cond = "4" 
    elif(shapeIndex = 'Sick'):
      DR1cond = "5"
    elif(shapeIndex = 'Cell'):
      DR1cond = "6"
    elif(shapeIndex = 'Distracted'):
      DR1cond = "7"
    else(shapeIndex = 'Unknown'):
      DR1cond = "99"
    row[1] = DR1cond
    updateRows.updateRow(row)
print'All done updating'
del updateRows 
del row

1 个答案:

答案 0 :(得分:0)

  • 使用2' ='当然。
  • 创建光标时,在字段列表中包含新代码字段,光标无法找到row[1]
  • 并且,如果代码字段很短或其他数字类型(这是有意义的),请删除' "'。