def save(self): # create gpx document from existing gpx file today = datetime.date.today().strftime("%Y-%m-%d") gpx_file = os.path.join(self.directory, today + '.xml') document = Document(children=[], name=today) if os.path.exists(gpx_file): document = document.readGPX(gpx_file) # add track to document segment = TrackSegment(points=self.track_points) document.append(Track(segments=[segment])) # add way points to document for wp in self.way_points: document.append(wp) # write or overwrite gpx file f = open(gpx_file, "wb") f.write(document.toGPX().toprettyxml(encoding="utf-8")) f.close() self.track_points = [] self.way_points = []
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ import sys import zmq from gps_data_pb2 import GpsData from gpxdata import TrackPoint, TrackSegment, Track, Document from zmq_ipc import generate_map socket = generate_map('gpx_logger')['gps'] gps_data = GpsData() segment = TrackSegment() try: while True: str = socket.recv() gps_data.ParseFromString(str) print gps_data point = TrackPoint(gps_data.lat, gps_data.lon, gps_data.alt) segment.appendPoint(point) except: pass track = Track( name="Copter Track", description="Track recorded using the copter's onboard GPS module") track.appendSegment(segment) doc = Document([track], name="Copter GPX Document") doc.writeGPX(sys.stdout)