I am fairly new to python and I am trying to understand what's happening here in these lines of code. I understand the algorithm and how it works but I am struggling to decode what is happening here in the code and how it is working to simplify the line segment.
This might sound a bit silly but if anyone could break this down for me it would be a great help! Cheers
Here is the Code:
def douglas_peuker_recursive(point_list, e):
dmax = 0
index = -1
for i in range(1, len(point_list)):
point = Point(point_list[i])
line = LineString([point_list[0], point_list[-1]])
d = point.distance(line)
if d > dmax:
index = i
dmax = d
if dmax > e:
r1 = douglas_peuker_recursive(point_list[:index+1], e)
r2 = douglas_peuker_recursive(point_list[index:], e)
return r1[:-1] + r2
else:
return [point_list[0], point_list[-1]]
Thank you!