Commit 2584d251 authored by Volker Krause's avatar Volker Krause
Browse files

Remove explicit timezone information from airport database

This is now provided by the generic timezone index, using the airport
coordinate and country.
parent 1fe380ac
......@@ -219,21 +219,6 @@ bool AirportDbGenerator::fetchCountries()
return true;
}
void AirportDbGenerator::lookupTimezones()
{
for (auto it = m_airportMap.begin(); it != m_airportMap.end(); ++it) {
if (!(*it).coord.isValid()) {
qDebug() << "Airport has no geo coordinate:" << (*it).label << (*it).iataCode << (*it).uri;
}
(*it).tz = m_tzDb.timezoneForLocation((*it).country, (*it).coord);
if ((*it).tz.isEmpty()) {
qDebug() << "Failed to find timezone for" << (*it).iataCode << (*it).label << (*it).country << (*it).coord.latitude << (*it).coord.longitude << (*it).uri;
++m_timezoneLoopupFails;
continue;
}
}
}
void AirportDbGenerator::improveCoordinates()
{
for (auto it = m_airportMap.begin(); it != m_airportMap.end(); ++it) {
......@@ -310,8 +295,7 @@ bool AirportDbGenerator::generate(QIODevice* out)
return false;
}
// step 2 augment the data with timezones and optimized OSM airport positions
lookupTimezones();
// step 2 augment the data with optimized OSM airport positions
improveCoordinates();
// step 3 index the names for reverse lookup
......@@ -346,33 +330,17 @@ static constexpr Airport airport_table[] = {
out->write("\"}, ");
CodeGen::writeCountryIsoCode(out, m_airportMap.value(it.value()).country);
out->write(", ");
CodeGen::writeTimezone(out, m_airportMap.value(it.value()).tz);
CodeGen::writeCoordinate(out, m_airportMap.value(it.value()).coord);
out->write("}, // ");
out->write(m_airportMap.value(it.value()).label.toUtf8());
out->write("\n");
}
out->write(R"(};
// airport coordinates in latitude/longitude pairs
// stored out of line of the airport_table to avoid alignment padding
static constexpr Coordinate coordinate_table[] = {
)");
// airport data tables - coordinates
// TODO: should be possible to squeeze into 48 bit per coordinate, as 10m resolution is good enough for us
for (auto it = m_iataMap.constBegin(); it != m_iataMap.constEnd(); ++it) {
const auto &airport = m_airportMap.value(it.value());
out->write(" ");
CodeGen::writeCoordinate(out, airport.coord);
out->write(", // ");
out->write(airport.iataCode.toUtf8());
out->write("\n");
}
out->write(R"(};
// reverse name lookup string table for unique strings
static const char name1_string_table[] =
)");
// TODO prefix compression
// TODO suffix compression -> see KPublicTransport, that has generic code for this
std::vector<Name1Index> string_offsets;
string_offsets.reserve(m_labelMap.size());
uint32_t label_offset = 0;
......
......@@ -57,7 +57,6 @@ private:
bool fetchAirports();
bool fetchCountries();
void merge(Airport &lhs, const Airport &rhs);
void lookupTimezones();
void improveCoordinates();
void indexNames();
......@@ -66,8 +65,6 @@ private:
// mapping IATA codes to indexed string fragments
QMap<QString, QVector<QString>> m_labelMap;
Timezones m_tzDb;
int m_iataCollisions = 0;
int m_coordinateConflicts = 0;
int m_countryConflicts = 0;
......
......@@ -35,9 +35,6 @@ namespace KnowledgeDb {
static_assert(alignof(Airport) <= sizeof(Airport), "Airport struct alignment too big!");
static constexpr auto airport_table_size = sizeof(airport_table) / sizeof(Airport);
static_assert(airport_table_size == sizeof(coordinate_table) / sizeof(KnowledgeDb::Coordinate), "Airport coordinate table size mismatch!");
static bool operator<(const Airport &lhs, IataCode rhs)
{
return lhs.iataCode < rhs;
......@@ -50,7 +47,7 @@ Coordinate coordinateForAirport(IataCode iataCode)
return {};
}
return coordinate_table[std::distance(std::begin(airport_table), it)];
return (*it).coordinate;
}
QTimeZone timezoneForAirport(IataCode iataCode)
......@@ -60,7 +57,7 @@ QTimeZone timezoneForAirport(IataCode iataCode)
return {};
}
return KnowledgeDb::toQTimeZone((*it).timezone);
return KnowledgeDb::toQTimeZone(KnowledgeDb::timezoneForLocation((*it).coordinate.latitude, (*it).coordinate.longitude, (*it).country));
}
KnowledgeDb::CountryId countryForAirport(IataCode iataCode)
......
......@@ -38,7 +38,7 @@ namespace KnowledgeDb {
struct Airport {
IataCode iataCode;
CountryId country;
Tz timezone;
Coordinate coordinate;
};
/** Returns the geographical coordinates the airport with IATA code @p iataCode is in. */
......
This diff is collapsed.
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