How to import the data from your apps and devices and create a heatmap from GPX files with Python.

I have 7 years’ worth of recorded walking activity on my computer. Over all these years these have been collected with several devices and apps, from stand-alone GPS-receiver, through SportsTracker to Garmin. Luckily, all of them have in common that the recorded route is available in GPX-format. Obtaining these files might not be as simple tough.

What is GPX?

GPS Exchange Format (GPX) is a GPS data format in XML. It is an open, license free, format that describes waypoints, tracks and routes. It is widely adopted and therefore the absolute standard interchanging location data. A location is stored as longitude-latitude (decimal degrees) pair and optionally extended with elevation (meters), time (UTC) and vendor specific information.

The example above is a track stored by Garmin, tracks stored by e.g. SportsTracker and Fitbit have the same structure but differ in the details.

The root element is gpx. It contains a metadata element and a trk element. The metadata specifies the source and creation time of the file. The trk element contains the stored track. A track consists of one or more segments, each stored in a trkseg element. At track level there are some fields with the name and type of the track. The specification allows for more fields but these are not used by e.g. Garmin.

The trkseg segment elements contains a list of track points (trkpt). A segment is a continuous set of points. If tracking is interrupted, e.g. lost connection or power failure, a new segment ought to be created.

A trkpt has the mandatory attributes lat and lon to specify the location. It has optional fields like time (time)and elevation (ele). The element extensions allows each device/app to add additional information like heartrate (hr in the Garmin example above), speed or course (not used by Garmin).

Tracks created with SportsTracker include the lon/lat attributes and the time and elevation elements. They have no extension like Garmin. The following data structure is assumed for parsing the GPX files:

<name>02-01-20 13:29</name>
<trkpt lat="52.12345" lon="6.31235">

Importing GPX files

For reading GPX files several Python libraries are available, like gpxpy. But for educational purposes an implementation is…

Continue reading:—-7f60cf5620c9—4