FileGDB
ArcGIS 10.4
Need to calculate elapsedSeconds column by first sorting on location_timestamp and then evaluate if PEP_land_name matches in row[n] and row[n+1]. If true, then set row[n+1] to elapsedSeconds value.
fields = ['PEP_land_name','location_timestamp','elapsedSeconds']
with arcpy.da.UpdateCursor(tracksToProcMonth, fields, sql, sql_clause=(None, 'ORDER BY location_timesatmp ASC')) as u_cur:
with arcpy.da.SearchCursor(tracksToProcMonth,fields, sql, sql_clause=(None, 'ORDER BY location_timestamp ASC')) as cursor:
for row in cursor:
firstlLand = row[0]
firstTimestamp = row[1]
try:
nextLand = cursor.next()[0]
nextTimestamp = cursor.next()[1]
if firstlLand == nextLand:
tdt = nextTimestamp - firstTimestamp
totSecs = tdt.total_seconds()
print 'totSecs: {}'.format(totSecs)
u_row = totSecs
u_cur.updateRow()
else:
totSecs = 0.00
u_row = totSecs
u_cur.updateRow()
I seem to be close in that I can arrive at the correct sort and evaluation, but I'm not exactly sure what to do about the updateCursor and setting the elapsedSeconds value in row[n+1]. In the attached image, OID 1 elapsedSeconds would be 0, OID 5 would be 5, and so on and on...
Solved! Go to Solution.
From a semantics perspective, this is a n-1 solution and not n+1. It is not possible to do an n+1 with a single cursor or a single loop through a cursor.