Skip to content

Commit

Permalink
add structure for PBF source, choose based on file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed Nov 13, 2024
1 parent 27e6323 commit b359efc
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/pfaedle/osm/OsmBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

// _____________________________________________________________________________
Expand Down
2 changes: 2 additions & 0 deletions src/pfaedle/osm/source/OsmSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class OsmSource {
virtual const OsmSourceRelation* nextRel() = 0;
virtual void cont() = 0;

virtual ~OsmSource() {};

virtual util::geo::Box<double> getBounds() = 0;

virtual void seekNodes() = 0;
Expand Down
78 changes: 78 additions & 0 deletions src/pfaedle/osm/source/PBFSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2024, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <[email protected]>

#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<double> 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
}
42 changes: 42 additions & 0 deletions src/pfaedle/osm/source/PBFSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <[email protected]>

#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<double> 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

0 comments on commit b359efc

Please sign in to comment.