I have some data of coordinates that I recorded. Unfortunatelly they seem to be not realy good. They jump sometimes over the map. So now I´m searching for some flattening or filtering algorithm that would make the route look more realistic.
Currently my only filter is to calculate the max possible meters travelled in a second (in bus or car or walking) and compare them with the coordinates, throwing those away, that are just not possible within a timeframe. So if a person can walk up to 2.5 meters in a second, and I have two coords that are 10 meters away from each other and they were recorded within two seconds, I try to find them and throw them away. This helps a little bit.
This is the code:
filters.max_possible_travel = function(data) {
//http://en.wikipedia.org/wiki/Preferred_walking_speed
//I switched to 16, as the route was made by driving with a bus...
var maxMetersPerSec = 16,
i, m, last, result = [];
for(i=0;i<data.length;i++) {
m = data[i];
if (last) {
// seconds between current and last coord
var diff = (m.created.getTime() - last.created.getTime()) / 1000;
// the maximum amount of meters a person,bus,car etc can make per sec.
var maxDistance = diff * maxMetersPerSec;
// the actual distance traveled
var traveledDistance = google.maps.geometry.spherical.computeDistanceBetween(last.googLatLng, m.googLatLng);
if (traveledDistance > maxDistance) {
continue;
} else {
result.push(m);
}
}
last = m;
}
return result;
};
To make things easier for you, I created this fiddle that already implements my first filter and also gives you the ability to add a new filter.
Some futher ideas I have:
- throw all coords away that are in a specific radius. This eventually would remove some disturbing coords, if you just stand around for a few minutes
- group all coords by n seconds frames and try to determine the most relevant in this block. Unfortunatelly I dont have any idea how :(
So I think this is a realy interessting issue, I hope you understand everything I was talking about. I thank You guys for any help!
Edit: I found something about Linear least squares and Kalman Filter. I´m into it, though because I´m absolutely not the math expert, I would appreciate any help in this.
EDIT 2 Progress :) I implemented the DouglasPeucker algorithm which @geocodezip promoted to me. The algorithm alone does not fix it all, but the combination of my current "max_possible_travel" it looks almost perfect. If I play a little bit with the second param it will get interessting. Please look at the new fiddle and make sure you check both the filters "walkfilter" and "gdouglaspeucker". http://jsfiddle.net/z4hB7/8/