From 7ccc303022f6b0f161119f7fca27ccf80da90e00 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 4 Mar 2024 13:35:04 +0100 Subject: [PATCH] write attributions.txt crediting OSM contributors, mention OSM copyright in README, closes #53 --- README.md | 4 ++++ src/cppgtfs | 2 +- src/pfaedle/gtfs/Writer.cpp | 28 ++++++++++++++++++++++++++++ src/pfaedle/gtfs/Writer.h | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e2cd1f..41d2aff 100644 --- a/README.md +++ b/README.md @@ -109,3 +109,7 @@ The following flags may be useful for debugging: # Configuration A default configuration file `pfaedle.cfg` can be found in this repo and will be installed with `make install`. Custom configuration files can be specified with the `-c` flag. If no `-c` flag is set, `pfaedle` will parse and merge the following cfg files in the given order (if present): `/etc/pfaedle/pfaedle.cfg`, `$HOME/.config/pfaedle/pfaedle.cfg`, `/pfaedle.cfg`. Values given in later files will overwrite earlier defined values. + +# Attribution + +Note that the `shapes.txt` produced by `pfaedle` is based on OpenStreetMap data, which is licensed under OdBL 1.0 (see [here](https://osm.org/copyright)). If you copy, distribute, transmit and adapt the shapefied GTFS feed, please credit the contributors of OpenStreetMap. diff --git a/src/cppgtfs b/src/cppgtfs index 7496330..d26d579 160000 --- a/src/cppgtfs +++ b/src/cppgtfs @@ -1 +1 @@ -Subproject commit 7496330a36bdfa7a3cdacff26d785a0607e63328 +Subproject commit d26d5794d396141905d71ecb8cd4f45e0120cba7 diff --git a/src/pfaedle/gtfs/Writer.cpp b/src/pfaedle/gtfs/Writer.cpp index 4ab5524..c11dbdf 100644 --- a/src/pfaedle/gtfs/Writer.cpp +++ b/src/pfaedle/gtfs/Writer.cpp @@ -345,6 +345,22 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { cannotWrite(curFileTg); } } + + curFile = getTmpFName(gtfsPath, ".pfaedle-tmp", "attributions.txt"); + curFileTg = gtfsPath + "/attributions.txt"; + fs.open(curFile.c_str()); + if (!fs.good()) cannotWrite(curFile, curFileTg); + writeAttribution(sourceFeed, &fs); + fs.close(); + + if (toZip) { +#ifdef LIBZIP_FOUND + moveIntoZip(za, curFile, "attributions.txt"); +#endif + } else { + if (std::rename(curFile.c_str(), curFileTg.c_str())) + cannotWrite(curFileTg); + } } catch (...) { #ifdef LIBZIP_FOUND zip_discard(za); @@ -363,6 +379,18 @@ void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const { } } +// ____________________________________________________________________________ +void Writer::writeAttribution(gtfs::Feed*, std::ostream* os) const { + auto csvw = ad::cppgtfs::Writer::getAttributionCsvw(os); + + csvw->flushLine(); + csvw->writeString("OpenStreetMap contributors"); + csvw->writeString("https://www.openstreetmap.org/copyright"); + csvw->writeInt(1); + + csvw->flushLine(); +} + // ____________________________________________________________________________ void Writer::writeFeedInfo(gtfs::Feed* f, std::ostream* os) const { auto csvw = ad::cppgtfs::Writer::getFeedInfoCsvw(os); diff --git a/src/pfaedle/gtfs/Writer.h b/src/pfaedle/gtfs/Writer.h index 6e32de7..e824edc 100644 --- a/src/pfaedle/gtfs/Writer.h +++ b/src/pfaedle/gtfs/Writer.h @@ -40,6 +40,7 @@ class Writer { void writeStopTimes(Feed* f, std::ostream* os) const; void writeLevels(Feed* f, std::ostream* os) const; void writePathways(Feed* f, std::ostream* os) const; + void writeAttribution(Feed* f, std::ostream* os) const; static void cannotWrite(const std::string& file, const std::string& file2); static void cannotWrite(const std::string& file);