Garmin Activities Visualized in Animated Maps: A Small Treat for Garmin Enthusiasts and Data Analysts

A short blog post on how to visualize multiple .gpx activities into compelling and interesting animated maps using Mapsy.art.

Peder Ward
CodeX
3 min readFeb 5, 2024

--

Example image created by the author using Mapsy.art. View the animated version below.

This article is a continuation of the publication titled “Explore and Uncover New Insights in Your Garmin Data Using a Data Science Approach”, which was published last year. In collaboration with Vasil Zidrovski, the person behind Mapsy.art, I am here to present a concise blog post introducing a practical method for animating your activities on a map using Python and Mapsy. Below, you’ll find an example showcasing some of my activites on animated maps:

gpx. files represented in animated map by Mapsy. The conversion to GIF has resulted in a reduction in quality.

To obtain the necessary .gpx files for this process, you can refer to the previously mentioned article, “Explore and Uncover New Insights in Your Garmin Data Using a Data Science Approach”, where I provide instructions on downloading the .gpx files using the Garmin-connect-export GitHub repository. After running the script you will have a folder containing files like this:

.gpx files after export.

Mapsy.art, currently a website, allows users to upload .gpx files, generates a video of their activities, and provides a link for access. Please note that there is an upload limit of 10MB, but you can upload .gpx, .fit, and .zip files.

Mapsy identifies activities in similar areas and organizes them into a single animated video. In cases where different .gpx files are from distinct areas, Mapsy splits the video into segments for each area. Due to the 10MB constraint, it can be helpful to categorize .gpx files by both area and activity if you have many or large files, aligning with the goal of showcasing similar activity types in the same area within the video.

To facilitate file management, I have developed a script that automatically categorizes .gpx files into folders based on their associated activity types (names). Leveraging XML parsing, the script extracts track names from .gpx files, creating a dictionary that maps activity types to corresponding file paths. Subsequently, the script iterates through the dictionary to generate folders for each activity type and copies the respective .gpx files into the appropriate folders. I’m unsure if this script works on .gpx files that are not exported from Garmin.

The script initiates by creating a dictionary:

import os
import shutil
import xml.etree.ElementTree as ET

folder_path = "garmin-connect-export/date_garmin_connect_export" # Replace with the actual path to your folder

# Create a dictionary to store track names and corresponding files
track_dict = {}

for filename in os.listdir(folder_path):
if filename.endswith(".gpx"):
file_path = os.path.join(folder_path, filename)

tree = ET.parse(file_path)
root = tree.getroot()

# Find the <name> element within the <trk> element
name_element = root.find(".//{http://www.topografix.com/GPX/1/1}trk/{http://www.topografix.com/GPX/1/1}name")

if name_element is not None:
track_name = name_element.text
print(f"Track name in {filename}: {track_name}")

# Add the file to the dictionary under the track name
if track_name in track_dict:
track_dict[track_name].append(file_path)
else:
track_dict[track_name] = [file_path]

else:
print(f"No track name found in {filename}")

It then utilizes the dictionary to sort the .gpx files into the correct folders:

# Iterate through the dictionary to create folders and copy files
for track_name, files in track_dict.items():
track_folder = os.path.join(folder_path, track_name)

if not os.path.exists(track_folder):
os.makedirs(track_folder)

for file_path in files:
destination_path = os.path.join(track_folder, os.path.basename(file_path))
shutil.copyfile(file_path, destination_path)
print(f"Copied {os.path.basename(file_path)} to {track_folder}")

After completing this process, zip the folder and upload it to mapsy.art. Following a processing period, you’ll receive a link to access the animated video, which can also be downloaded.

LinkedIn Profile — Vasil Zidrovski
LinkedIn Profile — Peder Ward

--

--

Peder Ward
CodeX

Data Scientist, MSc Cybernetics and robotics. LinkedIn Peder Ward