From dd05506c42223c0ca1941a5fa4582fdb4d5a4b0e Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 6 Nov 2023 17:59:29 +0100 Subject: [PATCH] update cppgtfs, add (hidden as of now, as the mode is not complete) option -F to keep additional non-standard GTFS fields --- src/cppgtfs | 2 +- src/pfaedle/PfaedleMain.cpp | 3 ++- src/pfaedle/config/ConfigReader.cpp | 6 +++++- src/pfaedle/config/PfaedleConfig.h | 4 ++++ src/pfaedle/gtfs/Writer.cpp | 21 +++++++++++++-------- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/cppgtfs b/src/cppgtfs index 8e1dd71..dce9b94 160000 --- a/src/cppgtfs +++ b/src/cppgtfs @@ -1 +1 @@ -Subproject commit 8e1dd71097cbc2fa1136522a2e2ba3cb574efe96 +Subproject commit dce9b94bd1e57bce1ba6242708234addc0db1d3c diff --git a/src/pfaedle/PfaedleMain.cpp b/src/pfaedle/PfaedleMain.cpp index c9305df..ca7ac3b 100644 --- a/src/pfaedle/PfaedleMain.cpp +++ b/src/pfaedle/PfaedleMain.cpp @@ -135,7 +135,8 @@ int main(int argc, char** argv) { if (!cfg.writeOverpass && !cfg.writeOsmfilter) LOG(INFO) << "Reading GTFS feed " << cfg.feedPaths[0] << " ..."; try { - ad::cppgtfs::Parser p(cfg.feedPaths[0]); + ad::cppgtfs::Parser p(cfg.feedPaths[0], false, + cfg.parseAdditionalGTFSFields); p.parse(>fs[0]); } catch (const ad::cppgtfs::ParserException& ex) { LOG(ERROR) << "Could not parse input GTFS feed, reason was:"; diff --git a/src/pfaedle/config/ConfigReader.cpp b/src/pfaedle/config/ConfigReader.cpp index e8190bc..53baf60 100644 --- a/src/pfaedle/config/ConfigReader.cpp +++ b/src/pfaedle/config/ConfigReader.cpp @@ -144,10 +144,11 @@ void ConfigReader::read(Config* cfg, int argc, char** argv) { {"stats", no_argument, 0, 14}, {"no-hop-cache", no_argument, 0, 15}, {"gaussian-noise", required_argument, 0, 16}, + {"keep-additional-gtfs-fields", no_argument, 0, 'F'}, {0, 0, 0, 0}}; char c; - while ((c = getopt_long(argc, argv, ":o:hvi:c:x:Dm:g:X:T:d:pP:", ops, 0)) != + while ((c = getopt_long(argc, argv, ":o:hvi:c:x:Dm:g:X:T:d:pP:F", ops, 0)) != -1) { switch (c) { case 1: @@ -219,6 +220,9 @@ void ConfigReader::read(Config* cfg, int argc, char** argv) { case 16: cfg->gaussianNoise = atof(optarg); break; + case 'F': + cfg->parseAdditionalGTFSFields = true; + break; case 'v': std::cout << "pfaedle " << VERSION_FULL << std::endl; exit(0); diff --git a/src/pfaedle/config/PfaedleConfig.h b/src/pfaedle/config/PfaedleConfig.h index 8da2750..7ad045c 100644 --- a/src/pfaedle/config/PfaedleConfig.h +++ b/src/pfaedle/config/PfaedleConfig.h @@ -9,6 +9,7 @@ #include #include #include + #include "ad/cppgtfs/gtfs/Route.h" #include "util/geo/Geo.h" @@ -36,6 +37,7 @@ struct Config { noTrie(false), noHopCache(false), writeStats(false), + parseAdditionalGTFSFields(false), gridSize(2000 / util::geo::M_PER_DEG), gaussianNoise(0) {} std::string dbgOutputPath; @@ -62,6 +64,7 @@ struct Config { bool noTrie; bool noHopCache; bool writeStats; + bool parseAdditionalGTFSFields; double gridSize; double gaussianNoise; @@ -85,6 +88,7 @@ struct Config { << "no-a-star: " << noAStar << "\n" << "no-trie: " << noTrie << "\n" << "no-hop-cache: " << noHopCache << "\n" + << "parse-additional-gtfs-fields: " << parseAdditionalGTFSFields << "\n" << "write-stats: " << writeStats << "\n" << "feed-paths: "; diff --git a/src/pfaedle/gtfs/Writer.cpp b/src/pfaedle/gtfs/Writer.cpp index 6cbde63..4ab5524 100644 --- a/src/pfaedle/gtfs/Writer.cpp +++ b/src/pfaedle/gtfs/Writer.cpp @@ -426,14 +426,15 @@ void Writer::writeAgency(gtfs::Feed* sourceFeed, std::ostream* os) const { ad::cppgtfs::Writer w; - auto csvw = ad::cppgtfs::Writer::getAgencyCsvw(os); + auto csvw = + ad::cppgtfs::Writer::getAgencyCsvw(os, sourceFeed->getAgencyAddFlds()); csvw->flushLine(); ad::cppgtfs::gtfs::flat::Agency fa; auto flds = Parser::getAgencyFlds(csvp.get()); while (p.nextAgency(csvp.get(), &fa, flds)) { - w.writeAgency(fa, csvw.get()); + w.writeAgency(fa, csvw.get(), sourceFeed->getAgencyAddFlds()); } } @@ -443,14 +444,15 @@ void Writer::writeStops(gtfs::Feed* sourceFeed, std::ostream* os) const { auto csvp = p.getCsvParser("stops.txt"); ad::cppgtfs::Writer w; - auto csvw = ad::cppgtfs::Writer::getStopsCsvw(os); + auto csvw = + ad::cppgtfs::Writer::getStopsCsvw(os, sourceFeed->getStopAddFlds()); csvw->flushLine(); ad::cppgtfs::gtfs::flat::Stop s; auto flds = Parser::getStopFlds(csvp.get()); while (p.nextStop(csvp.get(), &s, flds)) { - w.writeStop(s, csvw.get()); + w.writeStop(s, csvw.get(), sourceFeed->getStopAddFlds()); } } @@ -458,11 +460,13 @@ void Writer::writeStops(gtfs::Feed* sourceFeed, std::ostream* os) const { void Writer::writeRoutes(gtfs::Feed* sourceFeed, std::ostream* os) const { ad::cppgtfs::Writer w; - auto csvw = ad::cppgtfs::Writer::getRoutesCsvw(os); + auto csvw = + ad::cppgtfs::Writer::getRoutesCsvw(os, sourceFeed->getRouteAddFlds()); csvw->flushLine(); for (auto r : sourceFeed->getRoutes()) { - w.writeRoute(r.second->getFlat(), csvw.get()); + w.writeRoute(r.second->getFlat(), csvw.get(), + sourceFeed->getRouteAddFlds()); } } @@ -611,12 +615,13 @@ bool Writer::writeTrips(gtfs::Feed* sourceFeed, std::ostream* os) const { ad::cppgtfs::Writer w; bool hasFreqs = false; - auto csvw = ad::cppgtfs::Writer::getTripsCsvw(os); + auto csvw = + ad::cppgtfs::Writer::getTripsCsvw(os, sourceFeed->getTripAddFlds()); csvw->flushLine(); for (auto t : sourceFeed->getTrips()) { if (t.getFrequencies().size()) hasFreqs = true; - w.writeTrip(t.getFlat(), csvw.get()); + w.writeTrip(t.getFlat(), csvw.get(), sourceFeed->getTripAddFlds()); } return hasFreqs;