12

I'm looking for a way to apply spline interpolation to a gps track (GPX format). I am a regular QGIS user and also have GDAL libraries installed on my Mac if that helps.

Basically trail and ride information on MTB Project has a small set of points and actual paths are expanded via spline interpolation to reduce file sizes. I can download the tracks in gpx format, but they only contain a small set of points, giving me a track which resembles a jagged line which represents the small amount of points before interpolation. I want to apply a similar transformation to re-create the curved lines that are on the website, in a somewhat repeatable process that doesn't have me manually re-tracing each point with the spline drawing tool in QGIS.

enter image description here

Does anyone know of a way that I can easily apply spline interpolation to my gps track data to reproduce the splined track from MTB Project using free tools? Preferably on OSX?

5
  • FWIW, topofusion has this feature that I'm looking for, but I'm a mac user. So I'm looking for something that will work without Windows. topofusion.com/spline.php – Benzo Dec 31 '16 at 19:57
  • Actually, I used a windows pc and found topofusion does an okay job of smoothing the lines, but they are not interpolated in the same way as MTB project, so sometimes the curves happen in a way that is dissimilar and causes tracks to be even less accurate instead of more accurate, even after tweaking the parameters. – Benzo Jan 11 '17 at 15:41
  • I'm curious if you ever got a good solution for this question? For spline interpolation of mulitple tracks? – Simbamangu Jan 18 at 10:13
  • No. This is somewhat irrelevant for me now as MTB Project simply removed the interpolation and now just adds more datapoints and draws straight lines. So, the problem I was trying to solve got solved for me, at the expense of making already uploaded tracks change a bit, which means I have to rework a bit of the tracks I had already uploaded. But if I re-download them and import them in to qgis now, they will match the website without modification. – Benzo Jan 19 at 13:21
  • I was able to get tools that would give me a smooth line similar to my original path, but I needed one that passed through each of the control points, and I wasn't able to find a tool that did that. – Benzo Jan 19 at 13:22
8

Try using v.generalize tool from the Processing Toolbox. There are a number of algorithms in there that can generalize a line nicely.

Another possible solution could be the "Generalizer" plugin which was mentioned in this post, the plugin info in QGIS suggests that the tool is based on the v.generalizer Grass module anyway.

Just for reference below is an example of the output from the v.generalize tool. I used the default inputs for both the Chaiken and Hermite outputs, I have no doubt you could receive better results with a bit of research into the tool and specifically what the input values mean.

Update - The Snakes algorithm (not show in the orginal image below) with some tweaking of the alpha and beta parameters gives a smoother appearance on my test dataset.

Example of v.generalize output


References:

2
  • 1
    What is the 'snakes' algorithm? – Simbamangu Jan 19 at 5:34
  • Unfortunatley, this didn't work for me, because I needed the smooth line to pass through each of the defined path coordinates. This smooths the path and actually doesn't seem to pass through any of the points except the start and end. – Benzo Jan 19 at 13:24
3
+50

I feel awkward, but let me recommend QGIS + Spline Plugin as one of the options for your case.

  1. Yes, digitizing all points is cumbersome. But setting an appropriate Snap Option parameter can lessen a burden of the task.
  2. Other software capable to create Splines would be CAD (e.g. AutoCAD) or mathematical solution (e.g. R). If you choose CAD, its workflow is almost same, to repeat clicking points to add spline segments.
  3. If the bicycle track was an "ideal" spline curve, mathematically interpolated, best fit spline will be the solution. In reality, such spline rarely represents whole your track. You may end up splicing several curves, by attempting various smoothing parameters.
  4. When you use Spline Plugin, you can change parameters as you progress digitizing.

enter image description here

If your Tightness is set to 0.5 (default value), it can connect dense measurement points smoothly, and higher Tightness tries not to bend the curve at around those points.

You will notice Blue curve (0.9) fits better at gentle curve, and Orange (0.5) is good for tight corners. This flexibility is the best part of manually digitizing by Spline Plugin. If we try to do it by math equation, it can be nightmare.

  1. I am afraid generalize technique does not honor original data points. In other words, curve derived by generalizer does not go through your bicycle track.
2
  • Thanks for the point about the generalize technique, good to know. I'm probably not going to use the spline plugin option, as I'm trying to set parameters and run this process on multiple tracks, so this won't be a one off operation. I need a quickly repeatable process. – Benzo Jan 9 '17 at 19:43
  • Not accepting this as the answer, but awarding bounty for closest solution. Maybe if I take the time to figure out how to hack the spline plugin since I know some python, I can get it to iterate over the existing points automatically instead of doing manual digitization. Not sure how difficult that would be, but the source is out there for the plugin. – Benzo Jan 12 '17 at 14:32
3

There is a python script "gpx_interpolate" on Github which will do interpolation between GPX track points.

python3 gpx_interpolate.py -r 50 -d 3 INPUT.gpx

This will output a new file INPUT_interpolated.gpx with 50m (-r 50) between points and along spline of degree 3 (-d 3).

Options:

  • Resolution -r: distance between interpolated points. Default is 1m (change this if you have a long tracklog or you'll end up with a long wait and huge output file);
  • Degree -d: polynomial degree starting from 1 (straight lines) then up to degree 5 (2-5 all curves).
  • Number of points -n: force a certain number of output points (default is 0, no limit).

enter image description here

I've been using this to produce better estimates of actual tracks from aircraft flight logs where the GPS was set to a 10-second interval. In the example above setting resolution r to 50 interpolated an approximately 1-second interval which matches closely the real track. This is really helpful when using a low-res GPS track to correctly georeference images taken in flight.

Note that this script doesn't preserve the original trackpoints, but it is possible to merge the originals with the new interpolation using gpsbabel:

gpsbabel -i gpx -f INPUT.gpx -f INPUT_interpolated.gpx -x track,merge -o gpx -F INPUT_merged.gpx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.