Commit a8aefce2 authored by Volker Krause's avatar Volker Krause
Browse files

Add a basic "noise" filter for terminals

This removes terminal elements that are an order of magnitude smaller
than the rest. Those usually don't impact determining the location,
but occasionally are actually data issues.

Fixes the GRU test case.
parent 4c354511
......@@ -239,7 +239,7 @@ private Q_SLOTS:
QTest::newRow("GDN") << s("GDN") << 54.38234f << 18.46640f << 150;
QTest::newRow("GLA") << s("GLA") << 55.86405f << -4.43181f << 50;
QTest::newRow("GOT") << s("GOT") << 57.66771f << 12.29549f << 150;
QTest::newRow("GRU") << s("GRU") << -23.42560f << -46.48165f << 100;
QTest::newRow("GRU") << s("GRU") << -23.42560f << -46.48165f << 200;
QTest::newRow("GVA") << s("GVA") << 46.23020f << 6.10828f << 200;
QTest::newRow("HAJ") << s("HAJ") << 52.45849f << 9.69898f << 50;
QTest::newRow("HAM") << s("HAM") << 53.63214f << 10.00648f << 100;
......@@ -297,7 +297,6 @@ private Q_SLOTS:
#if 0
QEXPECT_FAIL("BUD", "closed terminal 1 (w8557242) interfering", Continue);
QEXPECT_FAIL("GLA", "airport is not a polygon in OSM", Continue);
QEXPECT_FAIL("GRU", "w777206182 interfering", Continue);
QEXPECT_FAIL("PRG", "private/military terminals 3 and 4 interfering", Continue);
QEXPECT_FAIL("PVG", "complicated", Continue);
QEXPECT_FAIL("RIG", "open polygon in OSM", Continue);
......
......@@ -28,6 +28,8 @@ enum {
StationToTerminalDistance = 75, // in meter
};
constexpr float TerminalSizeThreshold = 0.1; // percent of largest terminal size
void OSMAirportDb::load(const QString &path)
{
QFile f(path);
......@@ -54,7 +56,10 @@ void OSMAirportDb::load(const QString &path)
// load railway stations
OSM::for_each(m_dataset, [this](auto elem) { loadStation(elem); });
// once we have all elements grouped by airport, filter out elements we don't want to consider
for (auto &a : m_iataMap) {
filterTerminals(a.second);
filterStations(a.second);
}
......@@ -214,6 +219,22 @@ void OSMAirportDb::loadTerminal(OSM::Element elem)
}
}
void OSMAirportDb::filterTerminals(OSMAirportData &airport)
{
if (airport.terminals.empty()) {
return;
}
// sort by size, and drop micro terminals (which are usually data artifacts)
std::sort(airport.terminals.begin(), airport.terminals.end(), [](auto lhs, auto rhs) {
return OSM::distance(lhs.boundingBox().min, lhs.boundingBox().max) > OSM::distance(rhs.boundingBox().min, rhs.boundingBox().max);
});
const auto sizeThreshold = OSM::distance(airport.terminals[0].boundingBox().min, airport.terminals[0].boundingBox().max) * TerminalSizeThreshold;
airport.terminals.erase(std::partition(airport.terminals.begin(), airport.terminals.end(), [sizeThreshold](auto t) {
return OSM::distance(t.boundingBox().min, t.boundingBox().max) > sizeThreshold;
}), airport.terminals.end());
}
void OSMAirportDb::loadStation(OSM::Element elem)
{
const auto railway = elem.tagValue("railway");
......
......@@ -49,6 +49,7 @@ private:
void loadAirport(OSM::Element elem);
void loadAirport(OSM::Element elem, const QString &iataCode);
void loadTerminal(OSM::Element elem);
void filterTerminals(OSMAirportData &airport);
void loadStation(OSM::Element elem);
void filterStations(OSMAirportData &airport);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment