Update cursor for Row updation

897
1
10-24-2016 11:11 PM
MANESK
by
Occasional Contributor

i'm selecting a row and based on that row value i'm trying to update using update cursor for the "LAB field".
May be if condition is not working fine... Its not updated...
I dont know what is the error..Kindly suggest

arcpy.MakeFeatureLayer_management("PT_10K","Ten_FL")
arcpy.MakeFeatureLayer_management("PT_50k","Fifty_FL")

with arcpy.da.SearchCursor("PT_50k", ["ORIG_FID"]) as cursor:

i = 1
for row in cursor:
#print("Feature has x and y as of {1}{2}".format(row[1],row[2]))
arcpy.MakeFeatureLayer_management ("PT_50k","Layer")
arcpy.SelectLayerByAttribute_management("Layer","NEW_SELECTION",'"ORIG_FID" = {0}'.format(i))
arcpy.CopyFeatures_management("Layer","Fifty_FLY")
print i
i = i + 1
#arcpy.SelectLayerByLocation_management("Line_FL","WITHIN_A_DISTANCE","Trans_FL", "0.02 meters", "NEW_SELECTION")
arcpy.SelectLayerByLocation_management("Ten_FL","HAVE_THEIR_CENTER_IN","Fifty_FLY","14 meters","NEW_SELECTION")

arcpy.CopyFeatures_management("Ten_FL","Ten_temp1")
fields = ['LAB','X','Y']
with arcpy.da.UpdateCursor('Ten_temp1',fields) as cursor1:
print "Cursor Assigned"
j = 1
for row in cursor1:

x = row[1]
y = row[2]



if ((x == float(72.025000000129992)) and (y == float(35.77500392976323))):
row[0] = 'A'
print "row updated"
cursor1.updateRow(row)
elif x == 72.036 and y == 35.775:
row[0] = 'B'
print "row updated as B"
else:
print "not updated"
print j
j = j + 1
arcpy.Append_management("Ten_temp1","Ten_temp2","NO_TEST")

arcpy.SelectLayerByAttribute_management ("Layer","CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management("Ten_FL","CLEAR_SELECTION")
print "Selected Rows Cleared"
arcpy.DeleteFeatures_management("Ten_temp1")
arcpy.Delete_management("Layer")
arcpy.Delete_management("Fifty_FLY")

0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus

Could be the code formatting... however, you might want to fix it up so that errors can be assessed that aren't due to improper copy and paste

/blogs/dan_patterson/2016/08/14/script-formatting