diff --git a/CMakeLists.txt b/CMakeLists.txt index a9c10a8..ce5e3e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,12 @@ endif () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPFAEDLE_PRECISION=${PFAEDLE_PRECISION}") +find_package(LibZip) + +if (LIBZIP_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLIBZIP_FOUND=1") +endif() + # http://brianmilco.blogspot.de/2012/11/cmake-automatically-use-git-tags-as.html include(GetGitRevisionDescription) git_get_tag(VERSION_GIT) diff --git a/README.md b/README.md index e4cd8bc..aa1c082 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ # pfaedle Precise OpenStreetMap (OSM) map-matching for public transit schedules ([GTFS](https://developers.google.com/transit/gtfs/reference/) data). -First described in [this 2018 SIGSPATIAL paper](http://ad-publications.informatik.uni-freiburg.de/SIGSPATIAL_Sparse%20map%20matching%202018.pdf). +First described in [this 2018 SIGSPATIAL paper](http://ad-publications.informatik.uni-freiburg.de/SIGSPATIAL_Sparse%20map%20matching%202018.pdf). For a quick visual inspection of the shape quality, see for example the schedule data for Germany or Switzerland in our tool [TRAVIC](https://travic.app/?z=7&x=1261608.6&y=6430601.6). @@ -17,6 +17,7 @@ For a quick visual inspection of the shape quality, see for example the schedule * `cmake` * `gcc >= 5.0` (or `clang >= 3.9`) + * `libzip` (optional, for ZIP support) ## Building and Installation diff --git a/cmake/FindLibZip.cmake b/cmake/FindLibZip.cmake index 1b3efc5..cba9415 100644 --- a/cmake/FindLibZip.cmake +++ b/cmake/FindLibZip.cmake @@ -44,6 +44,6 @@ MARK_AS_ADVANCED(LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR LIBZIP_CONF_INCLUDE_DIR LIBZI IF (LIBZIP_FOUND) MESSAGE(STATUS "Found libzip: ${LIBZIP_LIBRARY}") -ELSE (LIPZIP_FOUND) +ELSE (LIBZIP_FOUND) MESSAGE(FATAL_ERROR "Could not find libzip") ENDIF (LIBZIP_FOUND) diff --git a/src/cppgtfs b/src/cppgtfs index 35ab19c..354fc1d 160000 --- a/src/cppgtfs +++ b/src/cppgtfs @@ -1 +1 @@ -Subproject commit 35ab19c313f96fec649fd0cb31c42d281f2c3b6e +Subproject commit 354fc1d68dd8a1cff43ae2cec9a4d294eabcb0c9 diff --git a/src/pfaedle/gtfs/Writer.cpp b/src/pfaedle/gtfs/Writer.cpp index d07a566..0380fc1 100644 --- a/src/pfaedle/gtfs/Writer.cpp +++ b/src/pfaedle/gtfs/Writer.cpp @@ -3,7 +3,10 @@ // Authors: Patrick Brosi #include + +#ifdef LIBZIP_FOUND #include +#endif #include #include @@ -20,7 +23,9 @@ using ad::cppgtfs::Parser; using ad::util::CsvWriter; +#ifdef LIBZIP_FOUND using ad::util::ZipCsvParser; +#endif using pfaedle::gtfs::Writer; using util::getTmpFName; @@ -39,6 +44,7 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { if (gtfsPath.size() == 0) gtfsPath = "."; +#ifdef LIBZIP_FOUND zip* za = 0; if (toZip) { @@ -65,6 +71,11 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { << ") Could not open ZIP file, reason was: " << errBuf; throw ad::cppgtfs::WriterException(ss.str(), tmpZip); } +#else + if (toZip) { + throw ad::cppgtfs::WriterException( + "Could not output ZIP file, pfaedle was compiled without libzip", path); +#endif } else { mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); } @@ -80,7 +91,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "agency.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -94,7 +107,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "stops.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -108,7 +123,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "routes.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -123,7 +140,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { writeCalendar(sourceFeed, &fs); fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "calendar.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -139,7 +158,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { writeCalendarDates(sourceFeed, &fs); fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "calendar_dates.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -155,7 +176,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { writeTransfers(sourceFeed, &fs); fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "transfers.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -171,7 +194,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { writeFares(sourceFeed, &fs); fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "fare_attributes.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -187,7 +212,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { writeFareRules(sourceFeed, &fs); fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "fare_rules.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -204,7 +231,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "pathways.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -221,7 +250,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "levels.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -236,7 +267,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "shapes.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -250,7 +283,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "trips.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -266,7 +301,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "frequencies.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -282,7 +319,9 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "stop_times.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); @@ -298,23 +337,29 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { fs.close(); if (toZip) { +#ifdef LIBZIP_FOUND moveIntoZip(za, curFile, "feed_info.txt"); +#endif } else { if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg); } } } catch (...) { +#ifdef LIBZIP_FOUND zip_discard(za); +#endif throw; } if (toZip) { +#ifdef LIBZIP_FOUND std::string targetZipPath = gtfsPath + "/" + zipFileName; if (!za) cannotWrite(targetZipPath); zip_close(za); if (std::rename(tmpZip.c_str(), targetZipPath.c_str())) cannotWrite(targetZipPath); +#endif } } @@ -334,6 +379,9 @@ void Writer::writeFeedInfo(gtfs::Feed* f, std::ostream* os) const { else csvw->skip(); csvw->writeString(f->getVersion()); + csvw->writeString(f->getContactEmail()); + csvw->writeString(f->getContactUrl()); + csvw->writeString(f->getDefaultLang()); csvw->flushLine(); } @@ -619,6 +667,7 @@ void Writer::cannotWrite(const std::string& file, const std::string& file2) { } // ___________________________________________________________________________ +#ifdef LIBZIP_FOUND void Writer::moveIntoZip(zip* za, const std::string& sourcePath, const std::string& targetPath) { zip_source_t* s; @@ -638,3 +687,4 @@ void Writer::moveIntoZip(zip* za, const std::string& sourcePath, cannotWrite(targetPath); } } +#endif diff --git a/src/pfaedle/gtfs/Writer.h b/src/pfaedle/gtfs/Writer.h index 41e169d..6e32de7 100644 --- a/src/pfaedle/gtfs/Writer.h +++ b/src/pfaedle/gtfs/Writer.h @@ -7,6 +7,9 @@ #include #include +#ifdef LIBZIP_FOUND +#include +#endif #include "Feed.h" #include "ad/cppgtfs/Parser.h" @@ -41,8 +44,10 @@ class Writer { static void cannotWrite(const std::string& file, const std::string& file2); static void cannotWrite(const std::string& file); +#ifdef LIBZIP_FOUND static void moveIntoZip(zip* za, const std::string& sourcePath, const std::string& targetPath); +#endif mutable std::ifstream _ifs; };