I am trying to extract the endpoint of a line with very fine scale and overlapping GPS data. I would normally just use the locn_id+1 but that doesn't work because the data were originally rarified. Likewise, spatial joins don't work because of the overlap.

I figure the best way to do this is to go back to the point file, create a column "End_id" and populate it with the next row's locn_id. I want to do this in Python, but I'm very new with update.cursor and can't figure it out.

Sadly I haven't gotten very far with a couple hours of looking around...

## fields to be added
Endid = "End_id"
Startid = "locn_id"

print "Adding column End_id"
arcpy.AddField_management(fc, Endid, "LONG")
print "Adding nrow+1 locn_id to End_id"
with arcpy.da.UpdateCursor(fc, Endid) as cursor:
    for row in cursor:

1 Answer 1


Here is one coding method for doing this process:

  1. Create an empty list variable (eg. myList = [])
  2. Create search cursor and within cursor for loop append all values of locn_id to list
  3. After cursor loop, (decrease indentations) on next statement pop out first index value from value list
  4. Create an update cursor and within cursor loop assign End_id row the first index value in list, (very next line still at same indentation level) pop out first index in list, and finally call cursor.updateRow(row) statement
  5. Continue looping...

With this logic the script will probably fail on the last record b/c the list will be empty (you could add a if condition check on the list variable to only pop if the list has a value), but will populate the preceding reocrds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.