git-svn-id: http://www.neo1973-germany.de/svn@152 46df4e5c-bc4e-4628-a0fc-830ba316316d

This commit is contained in:
Paulus 2008-09-16 15:18:22 +00:00
parent fe2c0a3a08
commit 63ca5e4b01

View file

@ -13,29 +13,29 @@ The file musst be closed, otherwise the file will be incomplete
class WriteGPX: class WriteGPX:
def __init__(self, filename): def __init__(self, filename):
self.filename = filename self.filename = filename
self.header = '<?xml version="1.0" encoding="UTF-8"?>\n\ self.header = '<?xml version="1.0" encoding="UTF-8"?>\n\
<gpx version="1.1"\n\ <gpx version="1.1"\n\
creator="WriteGPX - Python Class used in PyTracker.py"\n\ creator="WriteGPX - Python Class used in PyTracker.py"\n\
xmlns:xsi="http://www.w3.org/XML/1998/namespace"\n\ xmlns:xsi="http://www.w3.org/XML/1998/namespace"\n\
xmlns="http://www.topografix.com/GPX/1/1"\n\ xmlns="http://www.topografix.com/GPX/1/1"\n\
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n\ xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n\
<trk>\n\ <trk>\n\
<trkseg>\n' <trkseg>\n'
self.footer = '</trkseg>\n</trk>\n</gpx>\n' self.footer = '</trkseg>\n</trk>\n</gpx>\n'
with open(self.filename,'a') as file: with open(self.filename,'a') as file:
file.write(self.header) file.write(self.header)
def write(self, lat, lon, ele, time): def write(self, lat, lon, ele, time):
self.trackpoint = '<trkpt lat="%s" lon="%s">\n\ self.trackpoint = '<trkpt lat="%s" lon="%s">\n\
<ele>%s</ele>\n\ <ele>%s</ele>\n\
<time>%s</time>\n\ <time>%s</time>\n\
</trkpt>\n' % (lat, lon, ele, time) </trkpt>\n' % (lat, lon, ele, time)
with open(self.filename,'a') as file: with open(self.filename,'a') as file:
file.write(self.trackpoint) file.write(self.trackpoint)
def close(self): def close(self):
with open(self.filename,'a') as file: with open(self.filename,'a') as file:
file.write(self.footer) file.write(self.footer)