I have a very large dataset of GPS point that I am trying to write a python script for that will linearly compare one points to the ones around it. Original I was using the ID to determine which point to compare to the next one but do to how the points was collected the ID are not always in order, results in a lot of extra points being selected.
I believe the best solution would be to compare one point to all points within a 20’ foot buffer area of it. I am not sure how to best write a code that does this, I was thinking of creating an in-memory buffer of all points and then using that to select the points that I want to compare to each other.
Here is part of my original script that I am using now (this not using a buffer but an ID# to compare points):
JONum = arcpy.GetParameterAsText(0)
JO = "{}" "{}" "{}" "{}".format('JONumber = ',"'",JONum,"'")
OutPut = arcpy.GetParameterAsText(1)
arcpy.MakeFeatureLayer_management('GPSPipePoint', 'Temp', JO, OutPut)
arcpy.AddMessage('MN Feature Layer')
layer = 'GPS_GasMain_Temp'
fields = ['ID', 'NAME', 'SIGNAL', 'DEPTH', 'Z_COORD','OPERATORNAME','COLLECTIONDATE']
all_records = [i for i in arcpy.da.SearchCursor(layer,fields)]
all_records = sorted(all_records, key=lambda x: (x[6],x[7],x[1]))
ids_to_select2 = []
for index in range(1,len(all_records)-1): #Skip first and last record
if (abs(all_records[index][2] >= (1.2 * all_records[index-1][2]))):
ids_to_select2.append(all_records[index][0]) #If record >+-20%
sql2 = """{0} IN({1})""".format(arcpy.AddFieldDelimiters(datasource=layer, field=fields[0]), ','.join([str(i) for i in ids_to_select2])) #Build a query using ids_to_select list. For example 'GISID' IN(2023,2024)