During my recent trek in Colombia, my GPS watch battery died. I tried using my phone to track my voyage through the jungle and into the mountains, but honestly, until now I thought this was simply an unsuccessful attempt to track my voyage. I couldn’t view my trek on Garmin like I usually do, and I thought had no data to export.

Recently, as I was clearing the caches and files on my phone, I discovered some GPS data which coincided with my time in Colombia. My plan was to export the data and figure out an elegant way to plot it.

Attacking the Problem

As a follow-up to my last post on visualizing hiking statistics using Python, I decided to use Python to visualize this “missing” Colombia hike. Whereas before, I wanted to glean statistical information off of my hiking dataset, the Python use case here is slightly different. My primary motive here is to solve a problem – which is that I am currently unable to view a map of my hike.

Getting the Data

The first step here was to export the data on my phone as a GPX file, which I was able to do with a free GPS app that has the ability to load the orphaned GPS data on my phone. Once I had the data, it was time to start coding.

Importing the Hikes into Python for Visualization

First, install gpxpy, a GPX parser which you can find on Github.

Then, import the exported GPX tracks.

The parse function allows us to parse the data within the GPX files.

Next, I assign hike titles to strings which I will reference later on.

We can use loops to load in the latitude and longitude coordinates from each GPX file into separate arrays.

Now that the coordinates are stored in the arrays, I can plot the arrays to draw out my missing trek!

This is a plot of the latitude and longitude coordinates for the hike from El Cedral to La Pastora on Day 1 of the Colombia trek
This is a plot of the latitude and longitude coordinates for the hike from El Cedral to La Pastora on Day 1 of the Colombia trek

Here is what it looks like when you combine all of them into one plot.

 This is a plot of the latitude and longitude coordinates for all hikes on Days 1-4 of the Colombia trek
This is a plot of the latitude and longitude coordinates for all hikes on Days 1-4 of the Colombia trek

This is fantastic! Now, I can see my exact movements for each part of the trek, but there are still two improvements that can be made. First, it would be nice to see all the tracks in one figure, instead of seven separate plots. Also, it would be nice to see the locations of each of these – as of now, they are just drawings without any axes.

Visualizing all GPX Tracks in One Plot

The following piece of code allows us to accomplish this.

This is a plot of the latitude and longitude coordinates for all hikes on Days 1-4 of the Colombia trek , overlayed on one chart.
This is a plot of the latitude and longitude coordinates for all hikes on Days 1-4 of the Colombia trek, overlayed on one chart.

The finished product looks fantastic! This is exactly what I was looking for when I started this project! I can now see exactly where and how far I traveled during my trek. One final enhancement we can make to this is to distinguish each segment of the trek.

Distinguishing Each Part of the Trek in a Single Plot

Here is the code which allows us to distinguish the individual tracks in a single plot.

This is a plot of the latitude and longitude coordinates for all hikes on Days 1-4 of the Colombia trek , overlayed on one chart, which distinguishes between each segment of the trek.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.