I have a time that indicates a ship was detected at a certain point. I want to go through a list of the tracks of ships in the area(id'ed by their mmsi) and find the closest time right before the detection time and after the detection for each ship. This will help me ID which ship in the area was responsible for that detection at that time. The problem I have though is that I don't know how to find the closest time points.
import arcpy, os, datetime arcpy.env.overwriteOutput = True Source_File = "L:\\gathr\\indonesia\\Sara\\SAISData\\AAAS\\SAIS2.gdb\\AIS_Jan2016_CorrectTIme" field = "mmsi" mmsi_List = [row for row in arcpy.da.SearchCursor(Source_File,"mmsi")] mmsi_List1 = [x.encode('UTF8') for x in mmmsi_List] UniqueMmsi = set(mmsi_List1) UniqueMmsi_List = list(UniqueMmsi) print UniqueMmsi_List for mmsi_query in UniqueMmsi_List: out_layer = str(mmsi_query) in_features = "L:\\gathr\\indonesia\\Sara\\SAISData\\AAAS\\SAIS2.gdb\\AIS_Jan2016_CorrectTIme" #need 2 where clauses, one for the closest time before the detection time #and the other for the closest time after the detection time where_clause1 =??????????? where_str1 = str(where_clause1) arcpy.MakeFeatureLayer_management(in_features, out_layer) arcpy.SelectLayerByAttribute_management(out_layer, "NEW_SELECTION", where1_str)