Improving the Quality of GPS Track Data

Published

I love recording my GPS routes when hiking or going for a bike ride. I used Strava for many years, but recently switched to another generic app called MyTracks.

The new app does a pretty good job at capturing the GPS coordinates, but falls short of Strava’s ability to smooth-out routes and report accurate elevation (which I imagine Strava is looking-up backend rather than using the phone’s reported value).

Improving Collected GPS Data

I quickly learned that Smartphones and handheld GPS devices can be inaccurate at recording certain types of GPS information, like elevation1 2. Fortunately, there are techniques out there that can improve the quality of the GPS data. Three I looked at are:

  1. Map Matching – adjusting GPS points to match established road or trails, similar to routes “snapping” to the nearest road.
  2. Point Smoothing – mathematical formulas to smooth out data by removing outliers, taking rolling averages, etc.
  3. Elevation Data Correction – correcting elevation data by looking up actual elevation using an API or service rather than using the phone’s reported value.

1. Map Matching

Map Matching adjusts collected GPS points to “match-up” with existing roads or trails; your GPS device puts you near the trail, but the matching puts you directly on it. I imagine this process would be most effective when hiking very popular trails, or if you’re biking along roads.

Map Matching in action: the collected GPS coordinates (shown in black) have been “matched” to existing trails/roads (shown in yellow)

Here are two services I found that provide Map Matching via a REST API. While the endpoints are simple and easy to use, they are both have a limit number of coordinates they can process in a single request; be prepared to chop up your route and “match” over several requests.

  • MapBox Map Matching API – supports GET and POST requests limited to 100 coordinates; used this several years ago on a past client project, and while it didn’t always make a match, I was impressed when it did.
  • Geoapify – simple to use API with a free tier; backed by data from OpenStreetMap. No experience with this but looks promising.

2. Point Smoothing

The practice of point smoothing is not specific to GPS data. The idea is to eliminate (or correct) any data points that are higher than the adjacent points, providing a “smoothing” effect. There are many different libraries and algorithms available that are designed to perform this smoothing.

A quick Google search for “gpx track smoothing github” led me to the gpx-smoother module posted on GitHub. This module was designed to smooth GPX track elevation data. The interactive web demo allowed me to upload a recent GPX track and visually see the results of point smoothing.

The elevation profile for my original GPS capture is in blue, while the results of the smoothing algorithm are shown in green; screenshot taken from potter.ca

This particular module above is written for Node.js, however I am sure all programming languages have libraries that can perform smoothing techniques, it just might take a little searching 🙂 I did a sample search for “gpx point smoothing python” and found at least 2 promising results. Good luck!

3. Elevation Data Correction

For me, one of the most exciting parts about tracking GPS routes is viewing the elevation profile afterwards, especially if the trail has some steep vertical climb. As mentioned earlier, elevation data reported by phones and handheld devices is not the most accurate.

One way to improve elevation data is to take the GPS coordinate itself, and use it to look up the actual elevation for that location using publicly available elevation datasets.

Self-hosted Solution

My initial reaction was to attempt hosting an elevation correction service myself. I’d just need a REST interface in-front of some elevation data right? While it would be fun to build, the elevation datasets are quite large, and despite some dedicated people simplifying the process, I ultimately shied away from hosting my own service in favor of using public alternatives.

Elevation dataset sizes; screenshot taken of opentopodata.org in July of 2021

Publicly available REST APIs

Thankfully there are quite a few services available to look up elevation data for a given GPS coordinate. If operating within the free tiers like me, expect to work around rate limits like 100 coordinates per request, and 1000 requests a day. While this complicates building elevation correction into an processing pipeline, having the actual elevation data is worth it.

  • Google Maps Elevation API – no experience with this particular Google Maps API, but others I’ve used in the past have worked well. Just make sure to stay on top of those Billing Accounts / API Keys! Otherwise your service will cut right out 🙂
  • Open Topo Data Public API – free and open-source API powered by public datasets. Rate limits are in effect (understandably), so be ready to chop up your route. I am excited to use this service in an upcoming project.
  • Other alternatives are out there, have a look!

Correcting a Single Track (manual)

One great resource for correcting elevation data on GPX tracks is hosted on GPSVisualizer. The tool lets you upload a GPX file, and then download the corrected track, no strings attached. In my experience, this tool does a wonderful job of fixing the noisy elevation data collected by my phone. As of now, the service is manual, and works great when correcting the occasional hike or bike ride.

Conclusion

I imagine Strava is already leveraging these techniques (and more) behind the scenes to imrove GPS data collected when using their app, and they do a great job! Switching to a simpler collection app has shown me just how much processing is possible to help improve GPS data from a phone. As always the GIS world continues to fascinate, and I look forward to seeing what else is out there.

References

  1. How to Measure Altitude using Your Phone, “How do phones measure altitude” section
  2. Android: How to get accurate altitude? – Stack Overflow

Subscribe by Email

Enter your email address below to be notified about updates and new posts.


Comments

Loading comments..

No responses yet

Leave a Reply

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