Hello,
I have to update a feature class (16K records) based on four other feature classes. I am using the following code, which is working, but quite slow (about 35 min to complete). So, I was wondering if you guys could suggest some improvement to speed this up.
Thanks!
fieldsUpdate = ['OBJECTID','dr_Milepost','DR_distance_MP','Dr_Route','DR_DistanceFromRoute','DR_LANDOWNER_NAME','DR_PARCEL_NUMBER','DR_CountyName','DR_StateName']
fieldsM = ['OBJECTID', 'mile_post']
fieldsRoute = ['OBJECTID', 'id']
fieldsParcels = ['FID_Structures_NAD83_Update', 'LANDOWNER_NAME_1', 'PARCEL_NUMBER_1']
fieldsCounty = ['FID_Structures_NAD83_Update', 'CountyName_1', 'stateAbbr']
with arcpy.da.UpdateCursor(flStructure, fieldsUpdate) as cursorU:
for rowU in cursorU:
#Section to update the MilePost
strMatch = "OBJECTID =" + str(rowU[1])
#print(strMatch)
print("Mile post")
with arcpy.da.SearchCursor(flMilePost, fieldsM,where_clause=strMatch) as cursorM:
for rowM in cursorM:
print(u'{0}'.format(rowM[1]))
rowU[1] = rowM[1]
rowU[2] = rowU[2] * 3.28084
# Section to update the Route
print("Route")
strMatchRoute = "OBJECTID =" + str(rowU[3])
with arcpy.da.SearchCursor(flRouteLYR, fieldsRoute,where_clause=strMatchRoute) as cursorR:
for rowR in cursorR:
#print(u'{0}'.format(rowR[0]))
rowU[3] = rowR[1]
rowU[4] = rowU[4] * 3.28084
## Update using the intersect Parcels data
print("Parcels")
strMatchP = "FID_Structures_NAD83_Update ="+str(rowU[0])
with arcpy.da.SearchCursor(flParcels+"int", fieldsParcels,where_clause=strMatchP) as cursorP:
for rowP in cursorP:
rowU[5] = rowP[1]
rowU[6] = rowP[2]
## Update using the intersect County data
print("County")
strMatchC = "FID_Structures_NAD83_Update =" + str(rowU[0])
with arcpy.da.SearchCursor(flCounty+"int", fieldsCounty,where_clause=strMatchC) as cursorC:
for rowC in cursorC:
rowU[7] = rowC[1]
if rowC[2] == 'SD':
rowU[8] = 'South Dakota'
elif rowC[2]== 'ND':
rowU[8] = 'North Dakota'
elif rowC[2]== 'NE':
rowU[8] = 'Nebraska'
elif rowC[2]== 'MN':
rowU[8] = 'Minnesota'
elif rowC[2]== 'IA':
rowU[8] = 'Iowa'
else:
rowU[8] = ''
cursorU.updateRow(rowU)