forked from organicmaps/organicmaps-tmp
Added filter by distance
This commit is contained in:
parent
a9d26a936c
commit
700ba237e1
2 changed files with 25 additions and 4 deletions
|
@ -1,13 +1,19 @@
|
|||
#include "map/gps_track_filter.hpp"
|
||||
|
||||
#include "geometry/mercator.hpp"
|
||||
|
||||
#include "platform/settings.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
char const kMinHorizontalAccuracyKey[] = "GpsTrackingMinAccuracy";
|
||||
|
||||
// Minimal horizontal accuracy is required to skip 'bad' points.
|
||||
double constexpr kMinHorizontalAccuracyMeters = 50;
|
||||
|
||||
char const kMinHorizontalAccuracyKey[] = "GpsTrackingMinAccuracy";
|
||||
// Requires for points decimation to reduce number of close points.
|
||||
double constexpr kClosePointDistanceMeters = 15;
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -18,6 +24,8 @@ void GpsTrackFilter::StoreMinHorizontalAccuracy(double value)
|
|||
|
||||
GpsTrackFilter::GpsTrackFilter()
|
||||
: m_minAccuracy(kMinHorizontalAccuracyMeters)
|
||||
, m_lastPt(0, 0)
|
||||
, m_hasLast(false)
|
||||
{
|
||||
Settings::Get(kMinHorizontalAccuracyKey, m_minAccuracy);
|
||||
}
|
||||
|
@ -30,11 +38,20 @@ void GpsTrackFilter::Process(vector<location::GpsInfo> const & inPoints,
|
|||
|
||||
outPoints.reserve(inPoints.size());
|
||||
|
||||
for (auto const & inPt : inPoints)
|
||||
for (auto const & originPt : inPoints)
|
||||
{
|
||||
if (m_minAccuracy > 0 && inPt.m_horizontalAccuracy > m_minAccuracy)
|
||||
// Filter point by accuracy
|
||||
if (m_minAccuracy > 0 && originPt.m_horizontalAccuracy > m_minAccuracy)
|
||||
continue;
|
||||
|
||||
outPoints.emplace_back(inPt);
|
||||
// Filter point by close distance
|
||||
m2::PointD const & pt = MercatorBounds::FromLatLon(originPt.m_latitude, originPt.m_longitude);
|
||||
if (m_hasLast && MercatorBounds::DistanceOnEarth(pt, m_lastPt) < kClosePointDistanceMeters)
|
||||
continue;
|
||||
|
||||
m_lastPt = pt;
|
||||
m_hasLast = true;
|
||||
|
||||
outPoints.emplace_back(originPt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "platform/location.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
|
||||
#include "std/vector.hpp"
|
||||
|
||||
class GpsTrackFilter
|
||||
|
@ -17,5 +19,7 @@ public:
|
|||
|
||||
private:
|
||||
double m_minAccuracy;
|
||||
m2::PointD m_lastPt;
|
||||
bool m_hasLast;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue