wptogpx.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 '''
00004 example program to extract GPS data from a waypoint file, and create a GPX
00005 file, for loading into google earth
00006 '''
00007 
00008 import sys, struct, time, os
00009 
00010 from argparse import ArgumentParser
00011 parser = ArgumentParser(description=__doc__)
00012 parser.add_argument("wpfiles", metavar="WP_FILE", nargs="+")
00013 args = parser.parse_args()
00014 
00015 from pymavlink import mavutil, mavwp
00016 
00017 
00018 def wp_to_gpx(infilename, outfilename):
00019     '''convert a wp file to a GPX file'''
00020 
00021     wp = mavwp.MAVWPLoader()
00022     wp.load(infilename)
00023     outf = open(outfilename, mode='w')
00024 
00025     def process_wp(w, i):
00026         t = time.localtime(i)
00027         outf.write('''<wpt lat="%s" lon="%s">
00028   <ele>%s</ele>
00029   <cmt>WP %u</cmt>
00030 </wpt>
00031 ''' % (w.x, w.y, w.z, i))
00032 
00033     def add_header():
00034         outf.write('''<?xml version="1.0" encoding="UTF-8"?>
00035 <gpx
00036   version="1.0"
00037   creator="pymavlink"
00038   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
00039   xmlns="http://www.topografix.com/GPX/1/0"
00040   xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
00041 ''')
00042 
00043     def add_footer():
00044         outf.write('''
00045 </gpx>
00046 ''')
00047 
00048     add_header()
00049 
00050     count = 0
00051     for i in range(wp.count()):
00052         w = wp.wp(i)
00053         if w.frame == 3:
00054             w.z += wp.wp(0).z
00055         if w.command == 16:
00056             process_wp(w, i)
00057         count += 1
00058     add_footer()
00059     print("Created %s with %u points" % (outfilename, count))
00060 
00061 
00062 for infilename in args.wpfiles:
00063     outfilename = infilename + '.gpx'
00064     wp_to_gpx(infilename, outfilename)


mavlink
Author(s): Lorenz Meier
autogenerated on Sun May 22 2016 04:05:43