Commit 0440a16a authored by Nicola's avatar Nicola
Browse files

Douglas Peucker with Points

parent 63ca66a1
......@@ -89,32 +89,32 @@ def handleTrackpoint(tp):
#-------------------------------------------------------------------------------
def dpeuker(x,y,eps):
def dpeuker(points,eps):
xs = []
ys = []
xs.append(x[0])
ys.append(y[0])
dp(x,y,eps,xs,ys,0,len(x)-1)
xs.append(x[-1])
ys.append(y[-1])
xs.append(points[0].latitude)
ys.append(points[0].longitude)
dp(points,eps,xs,ys,0,len(points)-1)
xs.append(points[-1].latitude)
ys.append(points[-1].longitude)
return xs,ys
def dp(x,y,eps,xs,ys,iu,io):
def dp(points,eps,xs,ys,iu,io):
if iu+1 < io:
maxi=0
maxd=0.0
for i in range(iu+1,io):
dx = x[io] - x[iu]
dy = y[io] - y[iu]
d = fabs(y[i] - y[iu] - dy/dx * (x[i]-x[iu]))
dx = points[io].latitude - points[iu].latitude
dy = points[io].longitude - points[iu].longitude
d = fabs(points[i].longitude - points[iu].longitude - dy/dx * (points[i].latitude-points[iu].latitude))
if d>maxd:
maxi=i
maxd=d
if maxd>eps:
dp(x,y,eps,xs,ys,iu,maxi)
xs.append(x[maxi])
ys.append(y[maxi])
dp(x,y,eps,xs,ys,maxi,io)
dp(points,eps,xs,ys,iu,maxi)
xs.append(points[maxi].latitude)
ys.append(points[maxi].longitude)
dp(points,eps,xs,ys,maxi,io)
#-------------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment