Commit 9fd0485d authored by Sven Greiner's avatar Sven Greiner
Browse files

Clean up and some refactoring

parent d8bfe985
......@@ -4,20 +4,22 @@ from pylab import polyfit, polyval
from tkFileDialog import askopenfilename
from math import pi, sin, sqrt, cos, atan, fabs
#-------------------------------------------------------------------------------
class Point:
def __init__(self, latitude, longitude, time, elevation, speed=0, distance=0, segmentlength=0, vspeed=0, slope=0):
self.latitude = latitude
self.longitude = longitude
self.time = time
self.elevation = elevation
self.speed = speed
self.distance = distance
self.latitude = latitude
self.longitude = longitude
self.time = time
self.elevation = elevation
self.speed = speed
self.distance = distance
self.segmentlength = segmentlength
self.vspeed=0
self.slope=0
self.vspeed = vspeed
self.slope = slope
@staticmethod
def distanceBetween(p1, p2):
def distance(p1, p2):
if (p1.latitude,p1.longitude)==(p2.latitude,p2.longitude): return 0
f = 1.0/298.2572221
a = 6378137.0
......@@ -33,8 +35,22 @@ class Point:
H2 = (3*R+1)/(2*S)
return D*(1.0 + f*H1*sin(F)**2 * cos(G)**2 - f*H2*cos(F)**2 * sin(G)**2)
@staticmethod
def speed(p1, p2):
return p2.segmentlength / (p2.time - p1.time)
@staticmethod
def vspeed(p1, p2):
return (p2.elevation - p1.elevation) / (p2.time - p1.time)
@staticmethod
def slope(p1, p2):
return (p2.elevation - p1.elevation) / p2.segmentlength
def distanceTo(self, point):
return Point.distanceBetween(self, point)
return Point.distance(self, point)
#-------------------------------------------------------------------------------
def recalculatePointlist(points):
for i in xrange(len(points)):
......@@ -42,28 +58,14 @@ def recalculatePointlist(points):
if i>0:
point.segmentlength = point.distanceTo(points[i-1])
point.distance = points[i-1].distance + point.segmentlength
point.speed = point.segmentlength / (point.time - points[i-1].time)
point.slope = (point.elevation - points[i-1].elevation) / point.segmentlength
point.vspeed = (point.elevation - points[i-1].elevation) / (point.time - points[i-1].time)
point.speed = Point.speed(points[i-1], point)
point.vspeed = Point.vspeed(points[i-1], point)
point.slope = Point.slope(points[i-1], point)
return points
def interpol(x, y, lx):
i=0
while lx > x[i]:
i+=1
lu = x[i-1]
lo = x[i]
hu = y[i-1]
ho = y[i]
#-------------------------------------------------------------------------------
if lu==lo:
hx = hu
else:
hx = hu+ (ho-hu)/(lo-lu)*(lx-lu)
return hx
def handleGpx(gpx):
def parseTrack(gpx):
points = [];
tps = gpx.getElementsByTagName("trkpt")
for i in xrange(len(tps)):
......@@ -85,6 +87,8 @@ def handleTrackpoint(tp):
ele = (float(tp.getElementsByTagName("ele")[0].childNodes[0].data))
return tim, ele, lat, lon
#-------------------------------------------------------------------------------
def dpeuker(x,y,eps):
xs = []
ys = []
......@@ -112,13 +116,15 @@ def dp(x,y,eps,xs,ys,iu,io):
ys.append(y[maxi])
dp(x,y,eps,xs,ys,maxi,io)
#-------------------------------------------------------------------------------
filename = "samples/ol_egestorf.gpx"
dom = xml.dom.minidom.parse(filename)
data = handleGpx(dom)
if __name__ == "__main__":
filename = "samples/ol_egestorf.gpx"
dom = xml.dom.minidom.parse(filename)
track = parseTrack(dom)
print " lat | lon | distance | seglen | speed | slope | vspeed | elevation "
print "------------+------------+------------+------------+------------+------------+------------+------------"
print " lat | lon | distance | seglen | speed | slope | vspeed | elevation "
print "------------+------------+------------+------------+------------+------------+------------+------------"
for p in data:
print " %10.6f | %10.6f | %10.2f | %10.2f | %10.2f | %10.2f | %10.2f | %10.2f" % (p.latitude, p.longitude, p.distance, p.segmentlength, p.speed, p.slope, p.vspeed, p.elevation)
for p in track:
print " %10.6f | %10.6f | %10.2f | %10.2f | %10.2f | %10.2f | %10.2f | %10.2f" % (p.latitude, p.longitude, p.distance, p.segmentlength, p.speed, p.slope, p.vspeed, p.elevation)
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