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.
-
public boolean canRemovePreviousPosition(
-
Vector<GpsPosition> positions,
-
GpsPosition pos1) {
-
-
if(positions.size()<2) {
-
return false;
-
}
-
-
GpsPosition pos2 = positions.elementAt(
-
positions.size()-2 );
-
GpsPosition pos3 = positions.elementAt(
-
positions.size()-1 );
-
-
// Calculate last angle of trail
-
double latDelta = pos2.lat – pos3.lat;
-
double lonDelta = pos2.lon – pos3.lon;
-
-
// Calculate current angle
-
double latDelta2 = pos3.lat – pos1.lat;
-
double lonDelta2 = pos3.lon – pos1.lon;
-
double currentAngle =
-
-
// Get absolute value of direction change
-
double angleDelta =
-
-
// Check the tolerance (0.105 radians = 6 degrees)
-
if(angleDelta>0.105) {
-
return false;
-
} else {
-
return true;
-
}
-
}
March 29th, 2009 at 13:46
What about the 3rd dimension
March 29th, 2009 at 13:57
@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.
April 13th, 2009 at 12:08
Having a separate stream for latitude would be very nice. With optional period, minimum delta, filtering…
April 16th, 2009 at 21:49
@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.
May 4th, 2009 at 03:38
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
May 4th, 2009 at 20:53
@Phil: Thanks! Good idea to use the accelerometer for filtering. Basically we could could only record points when acceleration is noticed.
July 15th, 2009 at 16:24
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.