更新联接表类型上的游标错误:无法更新联接选项卡

2024-06-28 13:12:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个脚本,它连接两个特性层,并基于另一个表中的字段更新一个表的字段,该脚本将在ArcMap的pythonshell中运行。每个层的表包含大约60000个条目。在

第一个要素层称为assessortable,我将其与第二个要素层parceltable相结合。我的脚本使用Update Cursor根据assessortable中的字段计算parceltable中的字段。UpdateCursor脚本来自本指南:https://community.esri.com/blogs/richard_fairhurst/2014/11/08/turbo-charging-data-manipulation-with-python-cursors-and-dictionaries

但是,当我运行脚本时,我得到以下错误。在

错误:

Runtime error Traceback (most recent call last): File "", line 78, in TypeError: cannot update join table

我不知道如何解决这个问题,而且我对在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"```

Tags: andthein脚本nonefieldnewif