Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.simplify() removes points >max_distance away #99

Closed
nawagers opened this issue Oct 31, 2017 · 0 comments
Closed

.simplify() removes points >max_distance away #99

nawagers opened this issue Oct 31, 2017 · 0 comments

Comments

@nawagers
Copy link
Contributor

The simplify routine removes incorrect points due to 2 errors in the simplify_polyline function in geo.py.

The algorithm accepts a list of 'points' with points[0] and points[-1] being begin and end. The first task is to find the point furthest away from the line between 'begin' and 'end' so we should check all points between begin and end.

for point_no in range(len(points[1:-1])):
    point = points[point_no]

This starts at points[0] (begin) and ends at points[-3] skipping 'end' and one before 'end'. Instead, we should use:
for point_no in points[1:-1]:
or
for point_no in range(1,len(points)-1):

The second error is in the recursive call.
return (simplify_polyline(points[:tmp_max_distance_position + 2], max_distance) + simplify_polyline(points[tmp_max_distance_position + 1:], max_distance)[1:])

We want to call the function from (begin to anchor) and (anchor to end), removing one of the anchors during concatenation. The anchor point is tmp_max_distance_position and because of slicing we have to +1 (and +0), but in the code it was +2 (and +1), so not using the furthest point as an anchor, but whatever point came after that. What we want is:

return (simplify_polyline(points[:tmp_max_distance_position+1], max_distance) + simplify_polyline(points[tmp_max_distance_position:], max_distance)[1:])

nawagers added a commit to nawagers/gpxpy that referenced this issue Oct 31, 2017
@tkrajina tkrajina closed this as completed Apr 5, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants