diff --git a/src/shapevl/Collector.cpp b/src/shapevl/Collector.cpp index 33608a8..4d6f98c 100644 --- a/src/shapevl/Collector.cpp +++ b/src/shapevl/Collector.cpp @@ -36,6 +36,7 @@ double Collector::add(const Trip* oldT, const Shape* oldS, const Trip* newT, return 0; } + for (auto st : oldT->getStopTimes()) { if (st.getShapeDistanceTravelled() < 0) { // we cannot safely compare trips without shape dist travelled @@ -67,6 +68,21 @@ double Collector::add(const Trip* oldT, const Shape* oldS, const Trip* newT, std::vector newDists; LINE newL = getLine(newS, &newDists); + // check dist between anchor points + + if ((util::geo::latLngLen(oldL) * 1.0) / (oldL.size() * 1.0) > 1000) { + // most likely input with a degenerated shape - dont compare + _noOrigShp++; + return 0; + } + + if ((util::geo::latLngLen(newL) * 1.0) / (newL.size() * 1.0) > 1000) { + // most likely input with a degenerated shape - dont compare + _noOrigShp++; + return 0; + } + + std::vector> newLenDists; std::vector> oldLenDists; @@ -90,20 +106,26 @@ double Collector::add(const Trip* oldT, const Shape* oldS, const Trip* newT, } // convert (roughly) to degrees - double SEGL = 15.0 / util::geo::M_PER_DEG; + double SEGL = 25.0 / util::geo::M_PER_DEG; - auto old = _dCache.find(oldLCut); + double f = util::geo::webMercDistFactor(oldLCut.front()); + + // roughly half a meter + auto oldLCutS = util::geo::simplify(oldLCut, f * (0.5 / util::geo::M_PER_DEG)); + auto newLCutS = util::geo::simplify(newLCut, f * (0.5 / util::geo::M_PER_DEG)); + + auto old = _dCache.find(oldLCutS); if (old != _dCache.end()) { - auto match = old->second.find(newLCut); + auto match = old->second.find(newLCutS); if (match != old->second.end()) { fd = match->second; } else { - fd = util::geo::accFrechetDistCHav(oldLCut, newLCut, SEGL); - _dCache[oldLCut][newLCut] = fd; + fd = util::geo::accFrechetDistCHav(oldLCutS, newLCutS, SEGL); + _dCache[oldLCutS][newLCutS] = fd; } } else { - fd = util::geo::accFrechetDistCHav(oldLCut, newLCut, SEGL); - _dCache[oldLCut][newLCut] = fd; + fd = util::geo::accFrechetDistCHav(oldLCutS, newLCutS, SEGL); + _dCache[oldLCutS][newLCutS] = fd; } auto dA = getDa(oldSegs, newSegs); @@ -218,7 +240,6 @@ LINE Collector::getLine(const Shape* s, std::vector* dists) { ret.push_back({s->getPoints()[i].lng, s->getPoints()[i].lat}); (*dists).push_back(s->getPoints()[i].travelDist); } - return ret; } @@ -396,30 +417,36 @@ std::pair Collector::getDa(const std::vector& a, std::pair ret{0, 0}; // convert (roughly) to degrees - double SEGL = 15 / util::geo::M_PER_DEG; + double SEGL = 25 / util::geo::M_PER_DEG; double MAX = 50; for (size_t i = 0; i < a.size(); i++) { double fdMeter = 0; - auto old = _dACache.find(a[i]); + double f = util::geo::webMercDistFactor(a[i].front()); + + // roughly half a meter + auto aSimpl = util::geo::simplify(a[i], f * (0.5 / util::geo::M_PER_DEG)); + auto bSimpl = util::geo::simplify(b[i], f * (0.5 / util::geo::M_PER_DEG)); + + auto old = _dACache.find(aSimpl); if (old != _dACache.end()) { - auto match = old->second.find(b[i]); + auto match = old->second.find(bSimpl); if (match != old->second.end()) { fdMeter = match->second; } else { - fdMeter = util::geo::frechetDistHav(a[i], b[i], SEGL); - _dACache[a[i]][b[i]] = fdMeter; + fdMeter = util::geo::frechetDistHav(aSimpl, bSimpl, SEGL); + _dACache[aSimpl][bSimpl] = fdMeter; } } else { - fdMeter = util::geo::frechetDistHav(a[i], b[i], SEGL); - _dACache[a[i]][b[i]] = fdMeter; + fdMeter = util::geo::frechetDistHav(aSimpl, bSimpl, SEGL); + _dACache[aSimpl][bSimpl] = fdMeter; } if (fdMeter >= MAX) { ret.first++; - ret.second += util::geo::latLngLen(a[i]); + ret.second += util::geo::latLngLen(aSimpl); } } diff --git a/src/shapevl/Collector.h b/src/shapevl/Collector.h index 683c55b..ad285e9 100644 --- a/src/shapevl/Collector.h +++ b/src/shapevl/Collector.h @@ -31,7 +31,7 @@ struct lineCmp { } for (size_t i = 0; i < a.size(); i++) { - if (util::geo::dist(a[i], b[i]) > .000001) { + if (util::geo::dist(a[i], b[i]) > .00001) { return (a[i].getX() < b[i].getX()) || (a[i].getX() == b[i].getX() && a[i].getY() < b[i].getY()); ; diff --git a/src/util/geo/Geo.h b/src/util/geo/Geo.h index 3da7da0..255b707 100644 --- a/src/util/geo/Geo.h +++ b/src/util/geo/Geo.h @@ -1964,7 +1964,7 @@ inline double accFrechetDistCHav(const Line& a, const Line& b, double d) { for (size_t i = 1; i < p.size(); i++) { for (size_t j = 1; j < q.size(); j++) { float d = - util::geo::haversine(p[i], q[j]) * util::geo::dist(p[i], p[i - 1]); + util::geo::haversine(p[i], q[j]) * util::geo::haversine(p[i], p[i - 1]); ca[i * q.size() + j] = d + std::min(ca[(i - 1) * q.size() + j], std::min(ca[i * q.size() + (j - 1)],