我正在编写一个脚本,该脚本连接两个要素图层并基于另一个表中的字段更新一个表中的字段,以在ArcMap的Python shell中运行。每个图层的表包含约60,000个条目。
第一个要素层称为评估者表,我将其与第二个要素层称为宗地表结合在一起。我的脚本使用Update Cursor根据评估器中的字段来计算可包裹中的字段。 UpdateCursor脚本来自于本指南:https://community.esri.com/blogs/richard_fairhurst/2014/11/08/turbo-charging-data-manipulation-with-python-cursors-and-dictionaries
但是,当我运行脚本时,出现以下错误。
错误:
运行时错误 追溯(最近一次通话): 在第78行的文件“”中 TypeError:无法更新联接表
我不知道如何解决此问题,并且在学习使用ArcMap中的Python编码时还很陌生。任何帮助将不胜感激!
in_layer = parceltable
in_field = "APN_D"
join_table = assessortable
join_field = "APN_FORMATTED"
arcpy.AddJoin_management (in_layer, in_field, join_table, join_field)
print "tables joined!"```
#Calculate joined fields in parceltable:
sourceFC = assessortable
#Understanding the number coding for the source fields (AKA VALUE DICT):
#REPORT_URL = 0, GPDES = 1, MailingAddress = 2, MailingCityState = 3 MailingZip = 4, OwnerName = 5, COName = 6, APN_FORMATTED = 7
sourceFieldsList = ["APN_FORMATTED", "REPORT_URL", "GPDES", "MailingAddress", "MailingCityState", "MailingZip", "OwnerName", "COName", "APN_FORMATTED"]
# Use list comprehension to build a dictionary from a da SearchCursor
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
updateFC = parceltable
#Understanding the number coding for update fields (AKA UPDATEROW):
#APN_D = 0, ReportURL = 1, GPDES = 2, M_Address1 = 3, M_Address2 = 4, OWNER = 4, CAREOF = 6, APN_D = 7
updateFieldsList = ["APN_D", "ReportURL", "GPDES", "M_Address1", "M_Address2", "OWNER", "CAREOF", "APN_D"]
with arcpy.da.UpdateCursor(updateFC, updateFieldsList) as updateRows:
for updateRow in updateRows:
keyValue = updateRow[0]
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
if (valueDict[keyValue][0] != None):
# updateRow[1] is the new "ReportURL" field and valueDict[keyValue][0] is the "REPORT_URL" field
updateRow[1] = valueDict[keyValue][0]
if valueDict[keyValue][1] != None:
# updateRow[2] is the new GPDES field and valueDict[keyvalue][2] is the assessor's GPDES field
updateRow[2] = valueDict[keyValue][1]
if valueDict[keyValue][2] != None:
# updateRow[3] is the new Mailing Address Field and valueDict[keyvalue][3] is the assessor's Mailing Address.
updateRow[3] = valueDict[keyValue][2]
if (valueDict[keyValue][3] != None) and (valueDict[keyValue][4] != None):
# updateRow[4] is the new Mailing Address 2 field and valueDict[keyvalue][3] & [4] are the city, state, and zip
updateRow[4] = str(valueDict[keyValue][3]) + " " + str(valueDict[keyValue][4])
if (valueDict[keyValue][0] != None) and (valueDict[keyValue][1] != None) and (valueDict[keyValue][2] != None) and (valueDict[keyValue][3] != None) and (valueDict[keyValue][4] != None):
# updateRow[5] is the new Owner Name field and valueDict[keyvalue][5] is the assessor's owner name
updateRow[5] = valueDict[keyValue][5]
if (valueDict[keyValue][6] != None):
# updateRow[6] is the new Care Of field and valueDict[keyvalue][6] is the assessor's care of field
updateRow[6] = valueDict[keyValue][6]
updateRow[7] = "N" + str(updateRow[7])
updateRows.updateRow(updateRow)
del valueDict
print "All joined fields calculated!"
arcpy.RemoveJoin_management(parceltable, "")
print "Join removed"```