19 |
19 |
20 You should have received a copy of the GNU General Public License |
20 You should have received a copy of the GNU General Public License |
21 along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 ''' |
22 ''' |
23 |
23 |
24 import datetime |
24 import datetime, sys, os, time |
25 import sys |
|
26 import time |
|
27 from math import * |
25 from math import * |
28 import xml.etree.ElementTree as etree |
26 import xml.etree.ElementTree as etree |
29 from optparse import OptionParser |
27 from optparse import OptionParser |
30 |
28 |
31 # the path to the gnuplot binary |
|
32 gnuPlotCmd = 'gnuplot' |
|
33 |
|
34 parser = OptionParser('usage: %prog [options] input-file.gpx') |
29 parser = OptionParser('usage: %prog [options] input-file.gpx') |
|
30 parser.add_option('-g', action='store', type='string', dest='gnuplot', |
|
31 default='/usr/bin/gnuplot', help='PATH to the gnuplot binary (or .exe)', metavar='PATH') |
35 (options, args) = parser.parse_args() |
32 (options, args) = parser.parse_args() |
36 |
33 |
|
34 # the path to the gnuplot binary |
|
35 gnuPlotCmd = options.gnuplot |
|
36 if not os.path.exists (gnuPlotCmd): |
|
37 print gnuPlotCmd, 'does not exist' |
|
38 parser.print_help () |
|
39 sys.exit () |
37 |
40 |
38 if len(args) < 1: |
41 if len(args) < 1: |
39 parser.print_usage() |
42 parser.print_help () |
40 exit(2) |
43 sys.exit () |
41 |
|
42 |
44 |
43 # use the WGS-84 ellipsoid |
45 # use the WGS-84 ellipsoid |
44 rE = 6356752.314245 # earth's radius |
46 rE = 6356752.314245 # earth's radius |
45 a = 6378137.0 |
47 a = 6378137.0 |
46 b = 6356752.314245179 |
48 b = 6356752.314245179 |
92 tracksegs = [] |
94 tracksegs = [] |
93 sumx, sumy, sumz = 0.0, 0.0, 0.0 |
95 sumx, sumy, sumz = 0.0, 0.0, 0.0 |
94 ntot = 0 # total number of trackpoints (sum of segments) |
96 ntot = 0 # total number of trackpoints (sum of segments) |
95 |
97 |
96 # import xml data from files |
98 # import xml data from files |
|
99 if not os.path.exists (fname): |
|
100 print fname, 'does not exist' |
|
101 continue |
97 print 'opening file', fname |
102 print 'opening file', fname |
98 infile = open(fname) |
103 infile = open (fname) |
99 tree = etree.parse(infile) |
104 tree = etree.parse(infile) |
100 infile.close() |
105 infile.close() |
101 |
106 |
102 gpx = tree.getroot() |
107 gpx = tree.getroot() |
103 nsurl = gpx.tag.split ('}')[0][1:] # == 'http://www.topografix.com/GPX/1/1' |
108 nsurl = gpx.tag.split ('}')[0][1:] # == 'http://www.topografix.com/GPX/1/1' |
159 dr = (dy - dx) / 2 |
164 dr = (dy - dx) / 2 |
160 xmax += dr |
165 xmax += dr |
161 xmin -= dr |
166 xmin -= dr |
162 |
167 |
163 from subprocess import Popen, PIPE |
168 from subprocess import Popen, PIPE |
164 plot = Popen ([gnuPlotCmd], stdin=PIPE, stdout=PIPE, stderr=PIPE) |
169 try: |
|
170 plot = Popen ([gnuPlotCmd], stdin=PIPE, stdout=PIPE, stderr=PIPE) |
|
171 except Exception as e: |
|
172 print e, 'while executing', gnuPlotCmd |
|
173 sys.exit () |
165 |
174 |
166 range = 'set xrange [%f:%f]\nset yrange [%f:%f]\n' % (xmin, xmax, ymin, ymax) |
175 range = 'set xrange [%f:%f]\nset yrange [%f:%f]\n' % (xmin, xmax, ymin, ymax) |
167 plot.stdin.write (range) |
176 plot.stdin.write (range) |
168 |
177 |
169 curves = ','.join ("'-' with linespoints ti '%s: %d punten'" % t for t in npoints) |
178 curves = ','.join ("'-' with linespoints ti '%s: %d punten'" % t for t in npoints) |
170 plot.stdin.write ('plot ' + curves + '\n') |
179 plot.stdin.write ('plot ' + curves + '\n') |
171 |
180 |
172 plot.stdin.write ("\n".join (data)) |
181 plot.stdin.write ("\n".join (data)) |
173 plot.stdin.write ('\n') |
182 plot.stdin.write ('\n') |
174 plot.stdin.flush () |
183 plot.stdin.flush () |
175 raw_input ('druk') |
184 raw_input ('press enter to exit program') |