wptogpx.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 '''
4 example program to extract GPS data from a waypoint file, and create a GPX
5 file, for loading into google earth
6 '''
7 from __future__ import print_function
8 from builtins import range
9 
10 import time
11 
12 from argparse import ArgumentParser
13 parser = ArgumentParser(description=__doc__)
14 parser.add_argument("wpfiles", metavar="WP_FILE", nargs="+")
15 args = parser.parse_args()
16 
17 from pymavlink import mavwp
18 
19 
20 def wp_to_gpx(infilename, outfilename):
21  '''convert a wp file to a GPX file'''
22 
23  wp = mavwp.MAVWPLoader()
24  wp.load(infilename)
25  outf = open(outfilename, mode='w')
26 
27  def process_wp(w, i):
28  t = time.localtime(i)
29  outf.write('''<wpt lat="%s" lon="%s">
30  <ele>%s</ele>
31  <cmt>WP %u</cmt>
32 </wpt>
33 ''' % (w.x, w.y, w.z, i))
34 
35  def add_header():
36  outf.write('''<?xml version="1.0" encoding="UTF-8"?>
37 <gpx
38  version="1.0"
39  creator="pymavlink"
40  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
41  xmlns="http://www.topografix.com/GPX/1/0"
42  xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
43 ''')
44 
45  def add_footer():
46  outf.write('''
47 </gpx>
48 ''')
49 
50  add_header()
51 
52  count = 0
53  for i in range(wp.count()):
54  w = wp.wp(i)
55  if w.frame == 3:
56  w.z += wp.wp(0).z
57  if w.command == 16:
58  process_wp(w, i)
59  count += 1
60  add_footer()
61  print("Created %s with %u points" % (outfilename, count))
62 
63 
64 for infilename in args.wpfiles:
65  outfilename = infilename + '.gpx'
66  wp_to_gpx(infilename, outfilename)


mavlink
Author(s): Lorenz Meier
autogenerated on Sun Jul 7 2019 03:22:07