Commit 82ce75bd authored by Volker Krause's avatar Volker Krause
Browse files

Actually integrate the OSM airport coordinate code into the generator

parent be009fab
......@@ -5,6 +5,7 @@ add_executable(generate-knowledgedb
wikidata.cpp
airportdbgenerator.cpp
countrydbgenerator.cpp
osmairportdb.cpp
timezonedbgenerator.cpp
trainstationdbgenerator.cpp
util.cpp
......@@ -15,7 +16,7 @@ target_include_directories(generate-knowledgedb PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../knowledgedb
${CMAKE_CURRENT_BINARY_DIR}/..
)
target_link_libraries(generate-knowledgedb PRIVATE Qt5::Network Qt5::Gui)
target_link_libraries(generate-knowledgedb PRIVATE Qt5::Network Qt5::Gui KOSM)
find_program(XSLTPROC_EXECUTABLE xsltproc)
......@@ -41,21 +42,28 @@ osm_convert(INPUT airports.o5m OUTPUT airports-bbox.o5m ADD_BBOX ON)
osm_convert(INPUT airports-bbox.o5m OUTPUT airports-bbox.osm)
set(outfiles "")
macro(generate_db dbtype outfile)
function(generate_db dbtype outfile)
set(extra_args "")
if (ARGN)
set(extra_args "--osm-data=${ARGN}")
endif()
add_custom_command(
OUTPUT ${outfile}
COMMAND generate-knowledgedb -o ${CMAKE_CURRENT_SOURCE_DIR}/../knowledgedb/${outfile} -d ${dbtype}
COMMAND generate-knowledgedb -o ${CMAKE_CURRENT_SOURCE_DIR}/../knowledgedb/${outfile} -d ${dbtype} ${extra_args}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/timezones.colormap
${CMAKE_CURRENT_SOURCE_DIR}/timezones.png
${ARGN}
generate-knowledgedb
)
list(APPEND outfiles ${outfile})
endmacro()
set(outfiles ${outfiles} PARENT_SCOPE)
endfunction()
generate_db(country countrydb_data.cpp)
generate_db(timezone timezonedb_data.cpp)
generate_db(timezoneheader timezonedb_data_p.h)
generate_db(airport airportdb_data.cpp)
generate_db(airport airportdb_data.cpp ${OSM_PLANET_DIR}/airports-bbox.osm)
generate_db(trainstation trainstationdb_data.cpp)
add_custom_target(rebuild-knowledgedb DEPENDS ${outfiles} ${CMAKE_CURRENT_SOURCE_DIR}/timezones.png)
......@@ -234,6 +234,20 @@ void AirportDbGenerator::lookupTimezones()
}
}
void AirportDbGenerator::improveCoordinates()
{
for (auto it = m_airportMap.begin(); it != m_airportMap.end(); ++it) {
if (!(*it).coord.isValid()) {
continue;
}
const auto coord = osmDb.lookup((*it).iataCode, (*it).coord.latitude, (*it).coord.longitude);
if (coord.isValid()) {
(*it).coord.latitude = coord.latF();
(*it).coord.longitude = coord.lonF();
}
}
}
void KItinerary::Generator::AirportDbGenerator::indexNames()
{
for (auto it = m_airportMap.begin(); it != m_airportMap.end(); ++it) {
......@@ -296,8 +310,9 @@ bool AirportDbGenerator::generate(QIODevice* out)
return false;
}
// step 2 augment the data with timezones
// step 2 augment the data with timezones and optimized OSM airport positions
lookupTimezones();
improveCoordinates();
// step 3 index the names for reverse lookup
indexNames();
......
......@@ -19,6 +19,7 @@
#define KITINERARY_AIRPORTDBGENERATOR_H
#include <knowledgedb.h>
#include "osmairportdb.h"
#include "timezones.h"
#include <QHash>
......@@ -49,11 +50,15 @@ public:
int tzOffset;
KnowledgeDb::Coordinate coord;
};
OSMAirportDb osmDb;
private:
bool fetchAirports();
bool fetchCountries();
void merge(Airport &lhs, const Airport &rhs);
void lookupTimezones();
void improveCoordinates();
void indexNames();
QHash<QUrl, Airport> m_airportMap;
......
......@@ -35,6 +35,8 @@ int main(int argc, char **argv)
parser.addOption(dbOpt);
QCommandLineOption outputOpt({QStringLiteral("o"), QStringLiteral("output")}, QStringLiteral("Output file."), QStringLiteral("output file"));
parser.addOption(outputOpt);
QCommandLineOption osmOpt({QStringLiteral("m"), QStringLiteral("osm-data")}, QStringLiteral("OSM data file."), QStringLiteral("osm file"));
parser.addOption(osmOpt);
parser.addHelpOption();
parser.process(app);
......@@ -46,6 +48,7 @@ int main(int argc, char **argv)
if (parser.value(dbOpt) == QLatin1String("airport")) {
AirportDbGenerator gen;
gen.osmDb.load(parser.value(osmOpt));
return gen.generate(&out) ? 0 : 1;
} else if (parser.value(dbOpt) == QLatin1String("country")) {
CountryDbGenerator gen;
......
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