Track#
Tracks record where a person has been.
Internally, they contain an ordered list of Waypoint
describing a path.
Using Tracks#
Tracks are used like so:
Create the Track
Add some Waypoints to the Track
Perform some operations with the Track
Example#
Note
The following example assumes you are familiar with Waypoint
.
For example, let’s consider the following route:

We can represent this in GPSUtils using this code:
import gpsutils
track = gpsutils.Track()
waypoint1 = gpsutils.Waypoint(0, 0)
waypoint2 = gpsutils.Waypoint(0, 1)
waypoint3 = gpsutils.Waypoint(1, 1)
track.add_waypoint(waypoint1)
track.add_waypoint(waypoint2)
track.add_waypoint(waypoint3)
Check it#
>>> print(track)
Track(track=[Waypoint(latitude=0, longitude=0, elevation=0, time=2023-06-28 23:08:26.297853, name=, description=), Waypoint(latitude=0, longitude=1, elevation=0, time=2023-06-28 23:08:26.297853, name=, description=), Waypoint(latitude=1, longitude=1, elevation=0, time=2023-06-28 23:08:26.297853, name=, description=)], name=, description=)
>>> print(track.get_edges())
[(Waypoint(latitude=0, longitude=0, elevation=0, time=2023-06-28 23:08:26.297853, name=, description=), Waypoint(latitude=0, longitude=1, elevation=0, time=2023-06-28 23:08:26.297853, name=, description=)), (Waypoint(latitude=0, longitude=1, elevation=0, time=2023-06-28 23:08:26.297853, name=, description=), Waypoint(latitude=1, longitude=1, elevation=0, time=2023-06-28 23:08:26.297853, name=, description=))]
Working with Tracks#
Without doing anything too fancy, we can answer a few questions about our track:
Which pairs of points are connected? (How do we get from one place to another?)
How long is each edge between each pair of points? (How far is it from one place to another?)
How far is one point from the end (Are we there yet?)
Note
The following sections use the track imported in the Tutorial
# 1. How do we get from one place to another?
edges = track.get_edges()
# 2. How far is it from one place to another? (in metres)
edge_distances = track.edge_distances_m()
# 3. Are we there yet?
# For the sake of example, let's say we're at (46.57650000, 8.89280556)
remaining_distance = track.distance_to_end_m(gpsutils.Waypoint(46.57650000, 8.89280556))
Check it#
# 1. How do we get from one place to another?
>>> print(edges)
[(Waypoint(latitude=46.57608333, longitude=8.89241667, elevation=2376.0, time=2007-10-14 10:09:57+00:00, name=, description=), Waypoint(latitude=46.57619444, longitude=8.89252778, elevation=2375.0, time=2007-10-14 10:10:52+00:00, name=, description=)), (Waypoint(latitude=46.57619444, longitude=8.89252778, elevation=2375.0, time=2007-10-14 10:10:52+00:00, name=, description=), Waypoint(latitude=46.57641667, longitude=8.89266667, elevation=2372.0, time=2007-10-14 10:12:39+00:00, name=, description=)), (Waypoint(latitude=46.57641667, longitude=8.89266667, elevation=2372.0, time=2007-10-14 10:12:39+00:00, name=, description=), Waypoint(latitude=46.5765, longitude=8.89280556, elevation=2373.0, time=2007-10-14 10:13:12+00:00, name=, description=)), (Waypoint(latitude=46.5765, longitude=8.89280556, elevation=2373.0, time=2007-10-14 10:13:12+00:00, name=, description=), Waypoint(latitude=46.57638889, longitude=8.89302778, elevation=2374.0, time=2007-10-14 10:13:20+00:00, name=, description=)), (Waypoint(latitude=46.57638889, longitude=8.89302778, elevation=2374.0, time=2007-10-14 10:13:20+00:00, name=, description=), Waypoint(latitude=46.57652778, longitude=8.89322222, elevation=2375.0, time=2007-10-14 10:13:48+00:00, name=, description=)), (Waypoint(latitude=46.57652778, longitude=8.89322222, elevation=2375.0, time=2007-10-14 10:13:48+00:00, name=, description=), Waypoint(latitude=46.57661111, longitude=8.89344444, elevation=2376.0, time=2007-10-14 10:14:08+00:00, name=, description=))]
# 2. How far is it from one place to another? (in metres)
>>> print(edge_distances)
[14.99223974762043, 26.89468169228881, 14.090906258340778, 21.003272299148577, 21.43328858030647, 19.34812015069195]
# 3. Are we there yet?
>>> print(remaining_distance)
50.370657604293456
Where to go from here?#
Check out the Track API Reference
Try out the Tutorial if you haven’t already!