2018-08-14 15:33:23 +02:00
|
|
|
#!/usr/bin/env python
|
2018-08-22 19:34:20 +02:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import gpxpy
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
sys.exit('Usage: %s GPX_FILE' % sys.argv[0])
|
|
|
|
|
|
|
|
with open (sys.argv[1], 'r') as fh:
|
|
|
|
gpx = gpxpy.parse(fh)
|
|
|
|
|
|
|
|
json_out = []
|
|
|
|
for track in gpx.tracks:
|
|
|
|
for segment in track.segments:
|
|
|
|
for point in segment.points:
|
|
|
|
json_out.append({
|
|
|
|
'time': point.time.isoformat(),
|
|
|
|
'coords': {
|
|
|
|
'accuracy': point.horizontal_dilution,
|
|
|
|
'altitudeAccuracy': point.vertical_dilution,
|
2018-08-14 15:33:23 +02:00
|
|
|
'heading': point.course,
|
2018-08-22 19:34:20 +02:00
|
|
|
'latitude': point.latitude,
|
|
|
|
'longitude': point.longitude
|
|
|
|
}
|
|
|
|
})
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
2018-08-14 15:33:23 +02:00
|
|
|
with open(os.path.join(script_dir, '../tests/mock_gpx.json'), 'w') as fh:
|
2018-08-22 19:34:20 +02:00
|
|
|
json.dump(json_out, fh)
|