views:

136

answers:

5

I have a device that records GPS data. A reading is taken every 2-10 seconds. For an activity taking 2 hours there are a lot of GPS points.

Does anyone know of an algorithm for compressing the dataset by removing redundant data points. i.e. If a series of data points are all in a straight line then only the start and end point are required.

A: 

There is a research paper on Compressing GPS Data on Mobile Devices.

Additionally, you can look at this CodeProject article on Writing GPS Applications. I think the problem you will have is not for straight points, but curved roads. It all depends on how precise you want your path to be.

0A0D
Thanks Roboto - this info is interesting but its not directly what I was looking for. Thanks for the info anyway.
BENBUN Coder
A: 

i think that a vanilla zip algorithm would be the simplest and most effective for the widest variety of cases. Of course you wouldn't want to zip/unzip every few seconds but a clever use of a zip archive as a persistence mechanism would do.

Paul Sasik
-1 I don't think his problem is the compression of the data per se more than removal of redundant points.. this is what he means by compression
0A0D
+1  A: 

You probably want to approximate your path x(t), y(t) with a polynomial approximation of it. Are you looking for something like this: http://www.youtube.com/watch?v=YtcZXlKbDJY ???

Hamish Grubijan
+2  A: 

check out the Douglas Peucker Algorithm which is used to simplify a polygon. i´ve used this successfully to reduce the amount of gps waypoints when trasmitted to clients for displaying purposes.

Joachim Kerschbaumer
Thing to note with that solution is that there's loss of precision. Looks good btw, just not appropriate if each point needs to be recreated.
Paul Sasik
@psasik: A kalman filter should fix this. There will be an error distribution, but the more measurements that are taken over time, it will improve the precision
0A0D
psasik - thanks for the info - will take a look at http://www.codeproject.com/KB/cs/Douglas-Peucker_Algorithm.aspx
BENBUN Coder
take a look at the implementation of the NetTopologySuite project at http://code.google.com/p/nettopologysuite/ project.
Joachim Kerschbaumer
A: 

You can remove redundant points by performing a very basic simplification based on calculation of slope between subsequent points.

Here is a bit of but not complete C++ code presenting possible algorithm:

struct Point
{
   double x;
   double y;
};

double calculate_slope(Point const& p1, Point const& p2)
{
    //      dy     y2 - y1
    // m = ---- = ---------
    //      dx     x2 - x1
    return ((p2.y - p1.y) / (p2.x - p1.x));
}

// 1. Read first two points from GPS stream source
Point p0 = ... ;
Point p1 = ... ;

// 2. Accept p0 as it's first point

// 3. Calculate slope
double m0 = calculate_slope(p0, p1);

// 4. next point is now previous
p0 = p1;

// 5. Read another point
p1 = ... ;
double m1 = calculate_slope(p0, p1);

// 6. Eliminate Compare slopes
double const tolerance = 0.1; // choose your tolerance
double const diff = m0 - m1;
bool if (!((diff <= tolerance) && (diff >= -tolerance)))
{
    // 7. Accept p0 and eliminate p1

    m0 = m1;
}

// Repeat steps from 4 to 7 for the rest of points.

I hope it helps.

mloskot