We have 60 - 70 footprints for which the attributes are to be updated for 25 columns. Some of the columns will have coded values (Eg: Country, Metadata standard, Language). I've slightly modified the code provided in this thread Using UpdateCursor for joined field in ArcPy? (Second one - Code provided by Emil Brundage ). Since i don't know how to make the fields to be read in loop, for 25 fields i've used the same code. As an example i've only listed three fields.
Every column in the footprint is getting updated with the values from an excel sheet w.r.t "Name"column in both footprint & excel sheet. But "Language"column has not been updated and all i am getting is ""Create cursor has failed". "Language""column has coded values (English, Spanish, Portugese etc..). But the other columns with coded values are getting updated without any issues. Any suggestions on how to sort this out ?
import arcpy
footprint = arcpy.GetParameterAsText(0)
footprintFld1 = "Title"
footprintFld2 = "Date"
footprintFld3 = "Language"
footprintIdFld = arcpy.GetParameterAsText(1)
excel = arcpy.GetParameterAsText(2)
excelFld1 = "Title"
excelFld2 = "Date"
excelFld3 = "Language"
excelIdFld = arcpy.GetParameterAsText(3)
valueDi = dict ([(key, val) for key, val in arcpy.da.SearchCursor (excel, [excelIdFld, excelFld1])])
with arcpy.da.UpdateCursor (footprint, [footprintFld1, footprintIdFld]) as cursor:
for update, key in cursor:
if not key in valueDi:
continue
row = (valueDi [key], key)
cursor.updateRow(row)
del cursor
valueDi = dict ([(key, val) for key, val in arcpy.da.SearchCursor (excel, [excelIdFld, excelFld2])])
with arcpy.da.UpdateCursor (footprint, [footprintFld2, footprintIdFld]) as cursor:
for update, key in cursor:
if not key in valueDi:
continue
row = (valueDi [key], key)
cursor.updateRow(row)
del cursor
valueDi = dict ([(key, val) for key, val in arcpy.da.SearchCursor (excel, [excelIdFld, excelFld3])])
with arcpy.da.UpdateCursor (footprint, [footprintFld3, footprintIdFld]) as cursor:
for update, key in cursor:
if not key in valueDi:
continue
row = (valueDi [key], key)
cursor.updateRow(row)
del cursor
...
Runtime error
Traceback (most recent call last):
File "<string>", line 35, in <module>
RuntimeError: create cursor has failed
>>>
35th line in the code is // valueDi = dict ([(key, val) for key, val in arcpy.da.SearchCursor (excel, [excelIdFld, excelFld3])]) //. And, i am running this script as a tool from ArcToolbox.
-
Please remove the try/except statements from your code snippet so that you and we can see the error messages that Python provides (including line number).PolyGeo– PolyGeo ♦2017年02月06日 09:48:28 +00:00Commented Feb 6, 2017 at 9:48
-
I've removed the try/except statementsjoseph_k– joseph_k2017年02月06日 09:59:51 +00:00Commented Feb 6, 2017 at 9:59
-
Rather than struggle with domains, simply replace values in Excel table to codes.FelixIP– FelixIP2017年02月06日 19:32:18 +00:00Commented Feb 6, 2017 at 19:32
1 Answer 1
I think this looks "unusual":
if not key in valueDi:
continue
row = (valueDi [key], key)
cursor.updateRow(row)
Perhaps try this instead:
if key in valueDi:
row = (valueDi [key], key)
cursor.updateRow(row)
-
Tried it. Getting the same errorjoseph_k– joseph_k2017年02月06日 10:26:04 +00:00Commented Feb 6, 2017 at 10:26
-
File "<string>", line 35, in <module>, which means does it have to d anything with filename or field name in this line "// valueDi = dict ([(key, val) for key, val in arcpy.da.SearchCursor (excel, [excelIdFld, excelFld3])]) "joseph_k– joseph_k2017年02月06日 10:29:51 +00:00Commented Feb 6, 2017 at 10:29
-
I don't see
//
in your code.2017年02月06日 10:39:15 +00:00Commented Feb 6, 2017 at 10:39