Skip to content
Permalink
Browse files
Fix Douglas-Peucker algorithm
  • Loading branch information
Vort committed Jan 6, 2015
1 parent 045ca3b commit 3d0e9a26cb8fdd88b20f3feeb74b2185bbf15512
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
@@ -228,10 +228,9 @@
popped = False

if not config.getint('SCAN', 'deactivate_simplifying'):
lin.append(lin[0])
lin = douglas_peucker(lin, DOUGLAS_PEUCKER_EPSILON)
if len(lin) >= 2:
if lin[len(lin) - 1] == lin[len(lin) - 2]:
lin.pop()
lin.pop()
debug("line found; simplified to %s" % len(lin))
else:
debug("skipped simplifing")
@@ -242,10 +241,9 @@

if lin:
if not config.getint('SCAN', 'deactivate_simplifying'):
lin.append(lin[0])
lin = douglas_peucker(lin, DOUGLAS_PEUCKER_EPSILON)
if len(lin) >= 2:
if lin[len(lin) - 1] == lin[len(lin) - 2]:
lin.pop()
lin.pop()
debug("line post-found; simplified to %s" % len(lin))
else:
debug("skipped simplifing")
@@ -40,8 +40,8 @@ def point_line_distance(point, startline, endline):
"""

if (startline == endline):
return ((startline[0] - endline[0]) ** 2 + \
(startline[1] - endline[1]) ** 2) ** 0.5
return ((startline[0] - point[0]) ** 2 + \
(startline[1] - point[1]) ** 2) ** 0.5
else:
return abs((endline[0] - startline[0]) * (startline[1] - point[1]) - \
(startline[0] - point[0]) * (endline[1] - startline[1])) / \
@@ -67,7 +67,7 @@ def douglas_peucker(nodes, epsilon):

if farthest_dist > epsilon:
seg_a = douglas_peucker(nodes[0:farthest_node + 1], epsilon)
seg_b = douglas_peucker(nodes[farthest_node:-1], epsilon)
seg_b = douglas_peucker(nodes[farthest_node:], epsilon)
nodes = seg_a[:-1] + seg_b
else:
return [nodes[0], nodes[-1]]

0 comments on commit 3d0e9a2

Please sign in to comment.