# Picking points in a specific distance interval

I have a line of points in .shp file and the distance of the points varies. There can be 20 points in same place and then the distance can be something between 1 to 25 meters.

How can I pick points from the line every approx. 10m or 20 or 25 meters, so that instead of cluster of 10000 points in one line I would have a nice line with 1000 points every 20 meters?

• If I understand correctly in the Simplify line in it will move the points and I want to keep or maintain them where they are and just remove the excessives. the tolarence "For the POINT_REMOVE algorithm, the tolerance you specify is the maximum allowable offset of each vertex from its original location. This value may be reduced locally in some areas when the option is used to resolve topological errors." – VMJs Apr 10 at 9:26
• Okay, I need to keep points where they are, but thanks! – VMJs Apr 10 at 9:46
• Are the Points created in correct order or do you have some sorting field so it would be possible to construct a line using Points To Line tool as a start to solve the task? – BERA Apr 10 at 10:21
• Sorry, but your question has me confused because you mix and match the terms "lines" and "points". So.... does your shapefile contain lines or points? – Stu Smith Apr 11 at 6:49

You could try code below. The Points have to be created in correct order to be able to convert into a line, or have a sort field which you can use. I only have one line, you have to modify the code if you have multiple lines:

``````import arcpy

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'C:\Default.gdb' #Change
mindist = 200 #Change

points = [i for i in arcpy.da.SearchCursor(pointfc,['OID@','SHAPE@'])] #List all point oids and geometries

#Convert points to line. If they are not in correct order, and more than one, use Line_Field and Sort_Field
arcpy.PointsToLine_management(Input_Features=pointfc, Output_Feature_Class=r'in_memory\pointstoline')#, Line_Field=, Sort_Field=)
line = [i[0] for i in arcpy.da.SearchCursor(r'in_memory\pointstoline','SHAPE@')][0]

#Measure distances between points along the line
points_with_dist_along_line = [[p[0],line.measureOnLine(p[1])] for p in points if not p[1].disjoint(line)]

#Iterate over three points at a time and remove middle one if distance between first and last is <mindist*2
#Do this until oid of last point is reached

points_to_keep = points_with_dist_along_line
count=0
oid = -1
while oid != points_with_dist_along_line[-1][0]:
group = points_to_keep[count:count+3]
oid = group[-1][0]
if len(group)==3:
if group[2][1]-group[0][1]<mindist*2:
points_to_keep.pop(count+1)
else:
count+=1

#Create a new fc with the results
oids_to_keep = tuple([i[0] for i in points_to_keep])
sql = "{0} IN{1}".format(arcpy.Describe(pointfc).OIDFieldName, oids_to_keep)
arcpy.Select_analysis(in_features=pointfc, out_feature_class=outpointfc,
where_clause=sql)
``````