Optimizing Trail Recording

I coded a prototype how we could record fewer GPS positions in Mobile Trail Explorer and therefore save some memory but still have the same level of detail of the trail. Video might explain it best. Unoptimized recording is on the left and optimized trail is on the right.

The algorithm simply checks if the current direction have changed since last recorded position. If direction isn’t changed over the tolerance value then we can replace the last position with current position. Otherwise we only append the new position to the trail.

  1. public boolean canRemovePreviousPosition(
  2.         Vector<GpsPosition> positions,
  3.         GpsPosition pos1) {
  4.  
  5.     if(positions.size()<2) {
  6.         return false;
  7.     }
  8.  
  9.     GpsPosition pos2 = positions.elementAt(
  10.             positions.size()-2 );
  11.     GpsPosition pos3 = positions.elementAt(
  12.             positions.size()-1 );
  13.  
  14.     // Calculate last angle of trail
  15.     double latDelta = pos2.lat – pos3.lat;
  16.     double lonDelta = pos2.lon – pos3.lon;
  17.     double lastAngle = Math.atan(latDelta/lonDelta);
  18.  
  19.     // Calculate current angle
  20.     double latDelta2 = pos3.lat – pos1.lat;
  21.     double lonDelta2 = pos3.lon – pos1.lon;
  22.     double currentAngle =
  23.             Math.atan(latDelta2/lonDelta2);
  24.  
  25.     // Get absolute value of direction change
  26.     double angleDelta =
  27.             Math.abs(lastAngle – currentAngle);
  28.  
  29.     // Check the tolerance (0.105 radians = 6 degrees)
  30.     if(angleDelta>0.105) {
  31.         return false;
  32.     } else {
  33.         return true;
  34.     }
  35. }

This entry was posted in Java, MIDlet, Software Development and tagged , , , . Bookmark the permalink.

7 Responses to Optimizing Trail Recording

  1. Paul says:

    What about the 3rd dimension

  2. @Paul: Yes, you could add the altitude to this equation but since GPS doesn’t often give that precise altitude information I didn’t include it. That could be configurable option to optimization.

  3. Paul says:

    Having a separate stream for latitude would be very nice. With optional period, minimum delta, filtering…

  4. @Paul: Yes, it would be a good idea to make the minimum delta value as configurable. You can test the filtering in the latest beta version of MTE as I just implemented this to the trunk just few days ago.

  5. Phil says:

    Hi Tommi hi all,
    Firstly i would like to say you that your softs are wonderfull.

    For few new phone with accelerometer it should be possible to use accelerometer for filter the GPS data?

    Best regards

  6. @Phil: Thanks! Good idea to use the accelerometer for filtering. Basically we could could only record points when acceleration is noticed.

  7. mpele says:

    I am not so shure about mathematical values, but maybe it would be better to be:

    if(angleDelta>0.105 and angleDelta < 6.28-0.105)

    Diference between 2 and 358 degrees is 4 deegree and it should not trigger recording.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>