cygnal/scripts/gps_to_js.py
Phyks (Lucas Verney) 60f041f5a6 Move map from Leaflet to OpenLayers
Also add a way to use a mock GPX trace as geolocation provider.
2018-08-26 17:48:03 +02:00

35 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python
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,
'heading': point.course,
'latitude': point.latitude,
'longitude': point.longitude
}
})
break
break
script_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(script_dir, '../tests/mock_gpx.json'), 'w') as fh:
json.dump(json_out, fh)