I have a script that is used to update a line feature class with the start and end elevations based off of a shared ID number with a point feature class using list comprehension in arcpy. However I have an issue where the ID field from the points is a long integer and the ID field in the lines is a string field. Can I write something in my script to read in the integer values from the point layer as strings so that the list comprehension will work? Here is my current script that runs between matching integer field types, but not between mismatched field types:
from time import strftime
print "Start script: " + strftime("%Y-%m-%d %H:%M:%S")
import arcpy
#Transfer of Multiple Field Values between Feature Classes where there is a 1:1 Match between Field Sets
#keyValue fields must be identical field types (string, integer, etc.)
sourceFC = "Boxes"
strBoxID = str('Box_ID') #read the 'Box_ID' field as a string due to mismatching fieldtypes between boxes and lines
sourceFieldsList = [strBoxID, 'Elevation', strBoxID, 'Elevation'] # Your Source fields
# 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 = "LinesTest"
updateFieldsList = ['FBOX', 'F_ELEV', 'TBOX', 'T_ELEV'] # your updateFC fields
with arcpy.da.UpdateCursor(updateFC, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the Join value of the row being updated in a keyValue variable
keyValue = updateRow[0]
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
# transfer the values stored under the keyValue from the dictionary to the updated fields.
for n in range (1,len(sourceFieldsList)):
updateRow[n] = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
del valueDict
print "Finished script: " + strftime("%Y-%m-%d %H:%M:%S")