forked from tkrajina/gpxpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpxinfo
102 lines (76 loc) · 3.24 KB
/
gpxinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/env python
"""
Command line utility to extract basic statistics from a gpx file
"""
import pdb
import sys as mod_sys
import logging as mod_logging
import math as mod_math
import gpxpy as mod_gpxpy
#mod_logging.basicConfig(level=mod_logging.DEBUG,
# format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
def format_time(time_s):
if not time_s:
return 'n/a'
minutes = mod_math.floor(time_s / 60.)
hours = mod_math.floor(minutes / 60.)
return '%s:%s:%s' % (str(int(hours)).zfill(2), str(int(minutes % 60)).zfill(2), str(int(time_s % 60)).zfill(2))
def print_gpx_part_info(gpx_part, indentation=' '):
"""
gpx_part may be a track or segment.
"""
length_2d = gpx_part.length_2d()
length_3d = gpx_part.length_3d()
print('{}Length 2D: {:.3f}km'.format(indentation, length_2d / 1000.))
print('{}Length 3D: {:.3f}km'.format(indentation, length_3d / 1000.))
moving_time, stopped_time, moving_distance, stopped_distance, max_speed = gpx_part.get_moving_data()
print('%sMoving time: %s' % (indentation, format_time(moving_time)))
print('%sStopped time: %s' % (indentation, format_time(stopped_time)))
#print('%sStopped distance: %sm' % stopped_distance)
print('{}Max speed: {:.2f}m/s = {:.2f}km/h'.format(indentation, max_speed if max_speed else 0, max_speed * 60. ** 2 / 1000. if max_speed else 0))
uphill, downhill = gpx_part.get_uphill_downhill()
print('{}Total uphill: {:.2f}m'.format(indentation, uphill))
print('{}Total downhill: {:.2f}m'.format(indentation, downhill))
start_time, end_time = gpx_part.get_time_bounds()
print('%sStarted: %s' % (indentation, start_time))
print('%sEnded: %s' % (indentation, end_time))
points_no = len(list(gpx_part.walk(only_points=True)))
print('%sPoints: %s' % (indentation, points_no))
distances = []
previous_point = None
for point in gpx_part.walk(only_points=True):
if previous_point:
distance = point.distance_2d(previous_point)
distances.append(distance)
previous_point = point
print('{}Avg distance between points: {:.2f}m'.format(indentation, sum(distances) / len(list(gpx_part.walk()))))
print('')
def print_gpx_info(gpx, gpx_file):
print('File: %s' % gpx_file)
if gpx.name:
print(' GPX name: %s' % gpx.name)
if gpx.description:
print(' GPX description: %s' % gpx.description)
if gpx.author:
print(' Author: %s' % gpx.author)
if gpx.email:
print(' Email: %s' % gpx.email)
print_gpx_part_info(gpx)
for track_no, track in enumerate(gpx.tracks):
for segment_no, segment in enumerate(track.segments):
print(' Track #%s, Segment #%s' % (track_no, segment_no))
print_gpx_part_info(segment, indentation=' ')
def run(gpx_files):
if not gpx_files:
print('No GPX files given')
mod_sys.exit(1)
for gpx_file in gpx_files:
try:
gpx = mod_gpxpy.parse(open(gpx_file))
print_gpx_info(gpx, gpx_file)
except Exception as e:
mod_logging.exception(e)
print('Error processing %s' % gpx_file)
mod_sys.exit(1)
if __name__ == '__main__':
run(mod_sys.argv[1:])