Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing GPS Points

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.

like image 566
BENBUN Coder Avatar asked Dec 29 '09 15:12

BENBUN Coder


3 Answers

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.

like image 126
Joachim Kerschbaumer Avatar answered Sep 28 '22 10:09

Joachim Kerschbaumer


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 ???

like image 25
Hamish Grubijan Avatar answered Sep 28 '22 09:09

Hamish Grubijan


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.

like image 25
mloskot Avatar answered Sep 28 '22 08:09

mloskot