diff --git a/src/pfaedle/osm/OsmBuilder.cpp b/src/pfaedle/osm/OsmBuilder.cpp index 7696ae8..ce25f98 100644 --- a/src/pfaedle/osm/OsmBuilder.cpp +++ b/src/pfaedle/osm/OsmBuilder.cpp @@ -21,6 +21,7 @@ #include "pfaedle/osm/OsmBuilder.h" #include "pfaedle/osm/OsmFilter.h" #include "pfaedle/osm/Restrictor.h" +#include "pfaedle/osm/source/PBFSource.h" #include "pfaedle/osm/source/XMLSource.h" #include "util/Misc.h" #include "util/Nullable.h" @@ -41,6 +42,7 @@ using pfaedle::osm::source::OsmSourceNode; using pfaedle::osm::source::OsmSourceRelation; using pfaedle::osm::source::OsmSourceRelationMember; using pfaedle::osm::source::OsmSourceWay; +using pfaedle::osm::source::PBFSource; using pfaedle::osm::source::XMLSource; using pfaedle::trgraph::Component; using pfaedle::trgraph::Edge; @@ -87,8 +89,13 @@ void OsmBuilder::read(const std::string& path, const OsmReadOpts& opts, getKeptAttrKeys(opts, attrKeys); OsmFilter filter(opts); + OsmSource* source; - OsmSource* source = new XMLSource(path); + if (util::endsWith(path, ".pbf")) { + source = new PBFSource(path); + } else { + source = new XMLSource(path); + } // we do four passes of the file here to be as memory creedy as possible: // - the first pass collects all node IDs which are @@ -119,6 +126,8 @@ void OsmBuilder::read(const std::string& path, const OsmReadOpts& opts, LOG(DEBUG) << "Reading kept nodes..."; readNodes(source, g, intmRels, nodeRels, filter, bboxNodes, &nodes, &multNodes, &orphanStations, attrKeys[0], intmRels.flat, opts); + + delete source; } LOG(DEBUG) << "OSM ID set lookups: " << osm::OsmIdSet::LOOKUPS @@ -327,7 +336,13 @@ void OsmBuilder::filterWrite(const std::string& in, const std::string& out, // always empty NIdMultMap multNodes; - OsmSource* source = new XMLSource(in); + OsmSource* source; + + if (util::endsWith(in, ".pbf")) { + source = new PBFSource(in); + } else { + source = new XMLSource(in); + } BBoxIdx latLngBox = box; @@ -371,6 +386,8 @@ void OsmBuilder::filterWrite(const std::string& in, const std::string& out, readWriteRels(source, &wr, &ways, &nodes, filter, attrKeys[2]); wr.closeTags(); + + delete source; } // _____________________________________________________________________________ diff --git a/src/pfaedle/osm/source/OsmSource.h b/src/pfaedle/osm/source/OsmSource.h index 3707bb7..6eb788b 100644 --- a/src/pfaedle/osm/source/OsmSource.h +++ b/src/pfaedle/osm/source/OsmSource.h @@ -48,6 +48,8 @@ class OsmSource { virtual const OsmSourceRelation* nextRel() = 0; virtual void cont() = 0; + virtual ~OsmSource() {}; + virtual util::geo::Box getBounds() = 0; virtual void seekNodes() = 0; diff --git a/src/pfaedle/osm/source/PBFSource.cpp b/src/pfaedle/osm/source/PBFSource.cpp new file mode 100644 index 0000000..28f0a62 --- /dev/null +++ b/src/pfaedle/osm/source/PBFSource.cpp @@ -0,0 +1,78 @@ +// Copyright 2024, University of Freiburg, +// Chair of Algorithms and Data Structures. +// Authors: Patrick Brosi + +#include "pfaedle/osm/source/PBFSource.h" +#include "util/Misc.h" + +using pfaedle::osm::source::PBFSource; +using pfaedle::osm::source::OsmSourceNode; +using pfaedle::osm::source::OsmSourceWay; +using pfaedle::osm::source::OsmSourceRelation; +using pfaedle::osm::source::OsmSourceRelationMember; +using pfaedle::osm::source::OsmSourceAttr; + +// _____________________________________________________________________________ +PBFSource::PBFSource(const std::string& path) : _path(path) { + std::cout << "Init PBF source" << std::endl; +} + +// _____________________________________________________________________________ +const OsmSourceNode* PBFSource::nextNode() { + return 0; +} + +// _____________________________________________________________________________ +void PBFSource::seekNodes() { +} + +// _____________________________________________________________________________ +void PBFSource::seekWays() { +} + +// _____________________________________________________________________________ +void PBFSource::seekRels() { +} + +// _____________________________________________________________________________ +void PBFSource::cont() { +} + +// _____________________________________________________________________________ +const OsmSourceWay* PBFSource::nextWay() { + return 0; +} + +// _____________________________________________________________________________ +const OsmSourceRelationMember* PBFSource::nextMember() { + return 0; +} + +// _____________________________________________________________________________ +uint64_t PBFSource::nextMemberNode() { + return 0; +} + +// _____________________________________________________________________________ +const OsmSourceRelation* PBFSource::nextRel() { + return 0; +} + +// _____________________________________________________________________________ +const OsmSourceAttr PBFSource::nextAttr() { +} + + +// _____________________________________________________________________________ +util::geo::Box PBFSource::getBounds() { +} + +// _____________________________________________________________________________ +std::string PBFSource::decode(const char* str) const { + return str; // TODO +} + +// _____________________________________________________________________________ +std::string PBFSource::decode(const std::string& str) const { + return str; // TODO +} diff --git a/src/pfaedle/osm/source/PBFSource.h b/src/pfaedle/osm/source/PBFSource.h new file mode 100644 index 0000000..457ce44 --- /dev/null +++ b/src/pfaedle/osm/source/PBFSource.h @@ -0,0 +1,42 @@ +// Copyright 2024, University of Freiburg, +// Chair of Algorithms and Data Structures. +// Authors: Patrick Brosi + +#ifndef PFAEDLE_OSM_SOURCE_PBFSOURCE_H_ +#define PFAEDLE_OSM_SOURCE_PBFSOURCE_H_ + +#include "pfaedle/osm/source/OsmSource.h" + + +namespace pfaedle { +namespace osm { +namespace source { + +class PBFSource : public OsmSource { + public: + PBFSource(const std::string& path); + virtual const OsmSourceNode* nextNode(); + virtual const OsmSourceAttr nextAttr(); + virtual const OsmSourceWay* nextWay(); + virtual uint64_t nextMemberNode(); + virtual const OsmSourceRelationMember* nextMember(); + virtual const OsmSourceRelation* nextRel(); + virtual void cont(); + + virtual void seekNodes(); + virtual void seekWays(); + virtual void seekRels(); + + virtual util::geo::Box getBounds(); + + virtual std::string decode(const char* str) const; + virtual std::string decode(const std::string& str) const; + private: + std::string _path; +}; + +} // namespace source +} // namespace osm +} // namespace pfaedle + +#endif