I am matching data using a cursor, where one of the final steps is filling in a new attribute, match, with a value calculated during the cursor. This matching is done to an ID field in the original data that is often shared by many points (i.e. there are 200 points with VID 8, and they will all end up with the same match value, 284). I am looking for a way to speed up my script by setting the match value on all common VIDs so instead of running the cursor on every point data, it is only run on the unique VIDs (unfortunately other steps in my script make dissolving this data into multi-point impossible). If this were not done inside a Cursor, I would select by VID attribute and then use the calculate field tool. Is there a way to batch set values or get around the schema lock issue for the calculate field tool inside a cursor?
Here is a sample of the code (simplified) if I could use Calculate Field:
rows = arcpy.SearchCursor("logbook") #Temporarily a SearchCursor, but I've tried with UpdateCursor as well. for row in rows: if row.match > 0: #If the VID has already been matched, this will skip the calculations for it continue else: #(My matching and value calculating processes)# arcpy.SelectLayerByAttribute_management("logbook", "NEW_SELECTION", ' "VID" = ' + str(row.VID)) arcpy.CalculateField_management("logbook", "match", int(match_val)) del row, rows
Any thoughts? Or am I doomed to have a script that takes much longer than necessary?