107 sumx, sumy, sumz = 0.0, 0.0, 0.0 |
107 sumx, sumy, sumz = 0.0, 0.0, 0.0 |
108 ntot = 0 # total number of trackpoints (sum of segments) |
108 ntot = 0 # total number of trackpoints (sum of segments) |
109 |
109 |
110 # import xml data from files |
110 # import xml data from files |
111 if not os.path.exists (fname): |
111 if not os.path.exists (fname): |
112 print fname, 'does not exist' |
112 print (fname, 'does not exist') |
113 continue |
113 continue |
114 print 'opening file', fname |
114 print ('opening file', fname) |
115 infile = open (fname) |
115 infile = open (fname) |
116 tree = etree.parse(infile) |
116 tree = etree.parse(infile) |
117 infile.close() |
117 infile.close() |
118 |
118 |
119 gpx = tree.getroot() |
119 gpx = tree.getroot() |
132 eles = [float(trkpt.find(nsmap + 'ele').text) for trkpt in trkpts] |
132 eles = [float(trkpt.find(nsmap + 'ele').text) for trkpt in trkpts] |
133 try: |
133 try: |
134 times = [datetime.datetime.strptime(trkpt.find(nsmap + 'time' |
134 times = [datetime.datetime.strptime(trkpt.find(nsmap + 'time' |
135 ).text, timeformat) for trkpt in trkpts] |
135 ).text, timeformat) for trkpt in trkpts] |
136 except Exception as e: |
136 except Exception as e: |
137 print '-- trackpoint without time' |
137 print ('-- trackpoint without time') |
138 times = None |
138 times = None |
139 |
139 |
140 # save original trackseg for plotting |
140 # save original trackseg for plotting |
141 tracksegs.append ([ (lats[i], lons[i], eles[i]) for i in range(n) ]) |
141 tracksegs.append ([ (lats[i], lons[i], eles[i]) for i in range(n) ]) |
142 |
142 |
145 x, y, z = latlonele_to_xyz (lats[i], lons[i], eles[i]) |
145 x, y, z = latlonele_to_xyz (lats[i], lons[i], eles[i]) |
146 sumx += x |
146 sumx += x |
147 sumy += y |
147 sumy += y |
148 sumz += z |
148 sumz += z |
149 |
149 |
150 print 'segment %d, with %d points:' % (si, n) |
150 print ('segment %d, with %d points:' % (si, n)) |
151 ntot += n |
151 ntot += n |
152 |
152 |
153 tracks.append (tracksegs) |
153 tracks.append (tracksegs) |
154 npoints.append ((fname.replace ('_','\_'), ntot)) # underscore -> subscripts in gnuplot |
154 npoints.append ((fname.replace ('_','\_'), ntot)) # underscore -> subscripts in gnuplot |
155 print 'number of points in track %s = %d:' % (fname, ntot) |
155 print ('number of points in track %s = %d:' % (fname, ntot)) |
156 |
156 |
157 latm, lonm, elesum = xyz_to_latlonele (sumx, sumy, sumz) |
157 latm, lonm, elesum = xyz_to_latlonele (sumx, sumy, sumz) |
158 |
158 |
159 data = [] |
159 data = [] |
160 xmin, xmax = ymin, ymax = float ('inf'), float ('-inf') |
160 xmin, xmax = ymin, ymax = float ('inf'), float ('-inf') |
177 xmax += dr |
177 xmax += dr |
178 xmin -= dr |
178 xmin -= dr |
179 |
179 |
180 from subprocess import Popen, PIPE |
180 from subprocess import Popen, PIPE |
181 try: |
181 try: |
182 plot = Popen ([gnuPlotCmd], stdin=PIPE, stdout=PIPE, stderr=PIPE) |
182 plot = Popen ([gnuPlotCmd], stdin=PIPE, stdout=PIPE, stderr=PIPE, text=True) |
183 except Exception as e: |
183 except Exception as e: |
184 print e, 'while executing', gnuPlotCmd |
184 print (e, 'while executing', gnuPlotCmd) |
185 sys.exit () |
185 sys.exit () |
186 |
186 |
187 range = 'set xrange [%f:%f]\nset yrange [%f:%f]\n' % (xmin, xmax, ymin, ymax) |
187 range = 'set xrange [%f:%f]\nset yrange [%f:%f]\n' % (xmin, xmax, ymin, ymax) |
188 plot.stdin.write (range) |
188 plot.stdin.write (range) |
189 |
189 |