Commit 01b2aaf0 authored by Raphael's avatar Raphael
Browse files

Write to Shape funktioniert jetzt.

DP habe ich jetzt geändert, aber muss wahrscheinlich noch überarbeitet werden.
Außerdem müssen wir dem DP übergeben können, für welches Argument er den Algorithmus durchführen soll.
parent 87231b99
......@@ -91,16 +91,13 @@ def handleTrackpoint(tp):
#-------------------------------------------------------------------------------
def dpeuker(points,eps):
xs = []
ys = []
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(points,eps,xs,ys,iu,io):
result = []
result.append(Point(points[0].latitude, points[0].longitude, points[0].time, points[0].elevation))
dp(points,eps,result,0,len(points)-1)
result.append(Point(points[-1].latitude, points[-1].longitude, points[-1].time, points[-1].elevation))
return result
def dp(points,eps,result,iu,io):
if iu+1 < io:
maxi=0
maxd=0.0
......@@ -112,14 +109,13 @@ def dp(points,eps,xs,ys,iu,io):
maxi=i
maxd=d
if maxd>eps:
dp(points,eps,xs,ys,iu,maxi)
xs.append(points[maxi].latitude)
ys.append(points[maxi].longitude)
dp(points,eps,xs,ys,maxi,io)
dp(points,eps,result,iu,maxi)
result.append(Point(points[maxi].latitude, points[maxi].longitude, points[maxi].time, points[maxi].elevation))
dp(points,eps,result,maxi,io)
#-------------------------------------------------------------------------------
def writeToShape(tracks):
def writeToShape(track, simplified, shapename):
w = shapefile.Writer(shapefile.POLYLINE)
w.autoBalance = 1
w.field('ID', 'N', '16')
......@@ -127,26 +123,29 @@ def writeToShape(tracks):
w.field('Distance', 'N', '16')
w.field('Elevation', 'N', '16')
w.field('Speed', 'N', '16')
w.field('Slope', 'N', '16')
w.field('VerticalSpeed', 'N', '16')
parts = []
for i in xrange(len(tracks)):
track = tracks[i]
for j in xrange(len(track)):
w.field('Slope', 'N', '32')
w.field('VerticalSpeed', 'N', '32')
k = 0
for i in xrange(len(simplified) - 1):
parts = []
startPoint = simplified[i]
endPoint = simplified[i+1]
for j in range(k, len(track)):
point = track[j]
parts.append([point.latitude, point.longitude])
if(point.latitude == endPoint.latitude and point.longitude == endPoint.longitude):
k = j
break
w.line([parts])
w.record(ID=i,Time=track.time,Distance=track.distance,Elevation=track.elevation,Speed=track.speed,Slope=track.slope,VerticalSpeed=track.vspeed)
w.save('result')
w.record(ID=i,Time=endPoint.time-startPoint.time,Distance=endPoint.distance - startPoint.distance,Elevation=endPoint.elevation,Speed=endPoint.speed,Slope=endPoint.slope,VerticalSpeed=endPoint.vspeed)
w.save(shapename)
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 "------------+------------+------------+------------+------------+------------+------------+------------"
gpxname = "samples/ol_egestorf.gpx"
shapename = "result.shp"
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)
track = parseTrack(xml.dom.minidom.parse(gpxname))
simplified = dpeuker(track, 0.001)
recalculateTrack(simplified)
writeToShape(track, simplified, shapename)
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