burrscurr / linesman

Measuring the straightness of a gpx track
MIT License
2 stars 0 forks source link

Add an option for calculating deviation with respect to the best fit line #8

Open nzec opened 3 years ago

nzec commented 3 years ago

For reference: https://en.wikipedia.org/wiki/Simple_linear_regression

burrscurr commented 3 years ago

I think this is a great idea! Fitting the line with linear regression should result in an optimal squared deviation average, which IMHO should be a good straight line quality measure in general.

There are some aspects that need to be considered for implementation:

  1. linesman currently just calculates quality measures and fitting a line is somewhat a different thing. Creating a subcommand linesman fit distinct from to the default (measuring) linesman could be an option to avoid cluttering the command line interface.
  2. Interaction with spherical calculation: The straight line should be calculated in a sphere rather than with lon/lat coordinates (see #5). However, straight lines in a lon/lat coordinate system are not the shortest path on a sphere (like the earth) and vice-versa. Therefore, the simplest approach just fitting a linear function through the lat/lon points does not yield a correct solution in sphere. Though I think that this problem can be solved with a linear regression or some sort of ordinary least squares method, I'm not sure whether it is trivial. Do you have an idea on how to approach this?
  3. Sections with slower progress aka more points should not be more important in fitting than sections with less points. Therefore, it makes sense to use the gps track to interpolate the real movement and evaluate it compared to equidistant points on the straight line (see #4). Though I think that both features can be tackled separately, the interpolation-feature should be kept in mind when planning the implementation of the best-fit feature.
nzec commented 3 years ago

Methods to do this directly on the sphere are described here:

This would be the most accurate thing to do but would be very hard.

burrscurr commented 3 years ago

Ok, this might be doable, but its indeed very complicated.

In general, I think that linesman should prefer the gedoesic interpretation of "straight" line to the lat-lon-2d interpretation, as it makes more sense for long "straight" lines. On the other hand, mayhaps its common for gps trackers to not use a geodesic when determining the direct connection of two points – which would mean that implementing a geodesic regression wouldn't be of much practical use. Maybe input from user number 1 (geowizard) could help prioritizing this feature.