I'am trying to select some values from two tables, using dictionnary, the code is this :
import arcpy
from math import degrees, atan2
arcpy.env.workspace = "D:/Users/saadiya/Documents/ArcGIS/Default1.gdb"
arcpy.env.overwriteOutput = True
workspace = "C:/Saadia/SAFTOP/Parcelle et rivrains/simulation arcgis"
from time import strftime
print "Start script: " + strftime("%Y-%m-%d %H:%M:%S")
sourceFC = "Join_Output_15"
sourceFieldsList = ["RefName", "RefName_NW", "RefName_N", "RefName_NE", "RefName_E", "RefName_W", "RefName_S", "RefName_SE","RefName_SW"]
#0 1 2 3 4 5 6 7 8
# 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 = "t1"
updateFieldsList = ["src_RefName", "nbr_RefName", "Orientation","North", "South", "East", "West"]
#0 1 2 3 4 5 6
with arcpy.da.UpdateCursor(updateFC, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the src_RefName and nbr_RefName value of the row in a pair of keyValue variables
keyValue1 = updateRow[0]
#keyValue2 = updateRow[1]
# verify that the keyValues are in the Dictionary
if keyValue1 in valueDict :
# transfer the value stored under the keyValues from the dictionary to the updated field.
if (updateRow[2]== "North" and updateRow[1] != valueDict[keyValue1][1] and updateRow[1] != valueDict[keyValue1][2] and updateRow[1] != valueDict[keyValue1][3]) :
updateRow[3] = updateRow[1]
updateRows.updateRow(updateRow)
elif (updateRow[2] == "East" and updateRow[1] != valueDict[keyValue1][4]):
updateRow[5] = updateRow[1]
updateRows.updateRow(updateRow)
elif (updateRow[2] == "West" and updateRow[1] != valueDict[keyValue1][5]):
updateRow[6] = updateRow[1]
updateRows.updateRow(updateRow)
elif (updateRow[2] == "South" and updateRow[1] != valueDict[keyValue1][6] and updateRow[1] != valueDict[keyValue1][7] and updateRow[1] != valueDict[keyValue1][8])
updateRow[4] = updateRow[1]
updateRows.updateRow(updateRow)
print "Finished script: " + strftime("%Y-%m-%d %H:%M:%S")
but i get this error :
Traceback (most recent call last):
File "C:/Saadia/SAFTOP/Parcelle et rivrains/simulation arcgis/Code 15 12 2014/concatenation", line 42, in <module>
elif (updateRow[2] == "South" and updateRow[1] != valueDict[keyValue1][6] and updateRow[1] != valueDict[keyValue1][7] and updateRow[1] != valueDict[keyValue1][8]):
IndexError: tuple index out of range
Aucun commentaire:
Enregistrer un commentaire