How to: Create a heat map from GPS files (Nerd Alert)

You may have noticed the heat map in my May infographic post or the link that I added to the sidebar. I've been playing around with maps recently. I've never been very good at manually logging my training, but I've been tracking my workouts consistently via GPS since 2011, initially with my first iPhone, then with various watches. Having distance, time, and heart rate data from all of my workouts has been super useful from time to time to help figure out why I got sick, or why I felt particularly good on a given day. But for the most part, the actual GPS data hasn't really done much for me. UNTIL NOW.

Created using Mapbox Studio, with OpenStreetMap data

Created using Mapbox Studio, with OpenStreetMap data

Strava maintains a global heatmap of all the data generated by its users, and makes the data available to municipalities and researchers to help improve infrastructure for biking and running. They also generate personal heatmaps for premium users. I've subscribed to this before, and the heatmaps are pretty cool, but not worth the $6/month cost of Strava Premium. But as it turns out, it is possible to liberate all of the data from Strava and make similar graphics using only free tools available online.

To do this, I basically worked through a handful of tutorials, and then figured out some finishing touches on my own.

Get your hands on all of your data. All of the GPS data that I've generated is on Strava, and as it turns out they make it very easy to get all of the data out. Garmin Connect is a little bit more difficult, but there are ways to handle that as well. Actually, in addition to a bulk export from Strava, I set up Tapiriik to automatically sync my Garmin files to a folder in Dropbox so that the files are there for me in the future. Regardless of how you manage it, you want to end up with a collection of all of your GPS files in .gpx format. 

Combine all the data into a single .gpx file. This way, when you're doing the actual mapping you just have to handle a single file, rather than hundreds of files. Initially, when I was working with just a months worth of data, I found a webapp that can merge up to 20 files, which did the trick. My bulk Strava export contained 696 files so I had to search around a little bit to find something to manage them, but I managed it with GPSBabel - a free download and a very useful tool for GPS file conversion (I've used it before as part of a workflow to geocode photos).

Dig in to Mapbox. This is where things start to get more interesting. After signing up for a free account on Mapbox and navigating to Mapbox Studio, I created a new "Style", picked the look that I thought would work for me (Dark) and uploaded my data to Mapbox studio as a new layer. At this point, the tutorials ran out and I was left to my own experimentation to make the map look the way I wanted it. When you click on the layer that you just added, you have the option to change the data point type (fill, line, point or symbol) and the style (color, thickness, blur, etc.).

Created using Mapbox Studio, with OpenStreetMap data

Created using Mapbox Studio, with OpenStreetMap data

Build the Heat Map. Mapbox may have the functionality to create a true heat map by looking at spacial distribution of data points and mapping frequency to different colors - but if it does, I don't know how to take advantage of it. Instead, I duplicated the data layer several times, and played with the thickness and blur settings to give the effect of a heat map. There are also visibility settings which allow a particular layer to be limited to a range of zoom levels. This allowed me to use points for the zoomed-out view and fine lines to show the detail close up. The table below shows the settings that I settled on. Your milage may vary.

Color Zoom Type Radius/Width (px) Blur (px)
Red 8-22 Line 1 0
Yellow 8-22 Line 3 2
Red 4-8 Circle 4 3
Yellow 3-8 Circle 7 7
Green 3-22 Circle 10 10
Teal 3-22 Circle 15 10
Blue 3-22 Circle 20 10

Create a global view. Once I got everything looking just the way I wanted it, I discovered that the data that I added was not visible when zoomed out far enough to see the whole US or world - I'm not sure why. Rather than digging into this issue, I discovered that Mapbox can also import csv files. This turned out to be a great workaround - for US locations that I've been to, I manually created a .csv file with a list of locations that I wanted to show, in the following format:

City,State,Country,Latitude,Longitude
Minneapolis,MN,USA,44.977753,-93.265011
St Paul,MN,USA,44.953703,-93.089958

For European locations I created a second file, omitting the State column, and for all locations I used this tool to search for the lat/long coordinates. I imported these files, set them to only be visible on the few most-zoomed-out-levels, adjusted the color, blurred it a little, then leaned back and enjoyed my handiwork. An interactive version of the finished map can be found here.

Created using Mapbox Studio, with OpenStreetMap data

Created using Mapbox Studio, with OpenStreetMap data

That's all there is to it! I'm certainly not an expert on any of these tools, but feel free to leave a comment if you have any questions.

What are you doing with your GPS data?