Utilisation d'ArcDesktop 10.1 & Python 2.7: Je travaille sur un code qui recherche des valeurs dans 13 champs et, en fonction de ce qu'il trouve dans ces 13 champs, il concatène une chaîne et place le aboutir à un champ existant (vide).Problème lors de l'utilisation de UpdateCursor lors de la définition de la valeur
Il utilise un curseur de recherche pour rechercher les 13 champs. Puis utilise le résultat de cela dans un curseur de mise à jour pour concaténer la chaîne.
J'ai du mal à obtenir le résultat dans le champ en utilisant setValue - Line 40 du code ci-dessous @ urow.setValue (commentsField, easementType). Le message d'erreur est très inutile (RuntimeError: ERREUR 999999: Erreur d'exécution de la fonction.)
Je ne suis pas sûr comment obtenir correctement la valeur définie dans le champ souhaité. Toute aide serait grandement appréciée!
import arcpy, os, math
from itertools import izip
arcpy.env.workspace = "C:\\Users\\mdelgado\\Desktop\\WorkinDog.gdb"
#These are my variables
fc = "EASEMENTS"
commentsField = "Comments"
typeFields = ["ABANDONED", "ACCESS", "AERIAL", "BLANKET", "COMM", "DRAIN", "ELEC", "GEN_UTIL", "LANDSCAPE", "PARKING", "PIPELINE", "SAN_SEWR", "SIDEWALK", "SPECIAL", "STM_SEWR", "WATER"]
fieldNames = ["ABANDONED", "ACCESS", "AERIAL", "BLANKET", "COMMUNICATION", "DRAINAGE", "ELECTRIC", "GENERAL UTILITY", "LANDSCAPE", "PARKING", "PIPELINE", "SANITATION SEWER", "SIDEWALK", "SPECIAL", "STORM SEWER", "WATER"]
fieldValues = []
easementType = ""
#This is my search cursor
scursor = arcpy.SearchCursor(fc)
srow = scursor.next()
for field in typeFields:
srowValue = (srow.getValue(field))
fieldValues.append(srowValue)
srow = scursor.next()
print fieldValues
#This is my update cursor
ucursor = arcpy.UpdateCursor(fc)
for urow in ucursor:
#This is where I begin the loop to concatenate the comment field
for (value, name) in izip(fieldValues, fieldNames):
print str(value) + " " + name
#This is where I check each field to find out which types the easement is
if value == 1:
easementType = easementType + name + ", "
#This is where I format the final concatenated string
easementType = easementType[:-2]
print easementType
#This is where the field is updated with the final string using the cursor
urow.setValue(commentsField, easementType)
ucursor.updateRow(urow)
urow = cursor.next()
del urow
del ucursor
del srow
del scursor
-t-il correctement exécuter quelques lignes, puis pause? Avez-vous vérifié que la longueur du champ 'Comments' est suffisante pour accommoder le plus long easedType concaténé? – Erica
Excellente suggestion! Quand j'ai regardé cela, j'ai découvert que je référençais un alias de champ et non le nom réel du champ. Cela a résolu un problème. –