Skip to content

Commit

Permalink
add booleans for writing untagged nodes, ways, relations, and areas, …
Browse files Browse the repository at this point in the history
…set them to true by default
  • Loading branch information
patrickbr committed Nov 21, 2024
1 parent 3769c8e commit a032789
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
5 changes: 5 additions & 0 deletions include/osm2rdf/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ struct Config {
bool addWayNodeSpatialMetadata = false;
bool skipWikiLinks = false;

bool addUntaggedNodes = true;
bool addUntaggedWays = true;
bool addUntaggedRelations = true;
bool addUntaggedAreas = true;

int numThreads = std::thread::hardware_concurrency();

// Default settings for data
Expand Down
3 changes: 3 additions & 0 deletions include/osm2rdf/osm/CountHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace osm2rdf::osm {

class CountHandler : public osmium::handler::Handler {
public:
CountHandler(const osm2rdf::config::Config& config) : _config(config) {};
void node(const osmium::Node& node);
void relation(const osmium::Relation& relation);
void way(const osmium::Way& way);
Expand All @@ -45,6 +46,8 @@ class CountHandler : public osmium::handler::Handler {
bool _firstPassDone = false;
size_t _minId = std::numeric_limits<size_t>::max();
size_t _maxId = 0;

osm2rdf::config::Config _config;
};
}

Expand Down
28 changes: 11 additions & 17 deletions src/osm/CountHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,46 @@
// You should have received a copy of the GNU General Public License
// along with osm2rdf. If not, see <https://www.gnu.org/licenses/>.

#include "osm2rdf/osm/CountHandler.h"

#include <iostream>

#include "osm2rdf/osm/CountHandler.h"

// ____________________________________________________________________________
void osm2rdf::osm::CountHandler::prepare_for_lookup() {
_firstPassDone = true;
}
void osm2rdf::osm::CountHandler::prepare_for_lookup() { _firstPassDone = true; }

// ____________________________________________________________________________
void osm2rdf::osm::CountHandler::node(const osmium::Node& node){
void osm2rdf::osm::CountHandler::node(const osmium::Node& node) {
if (node.positive_id() < _minId) _minId = node.positive_id();
if (node.positive_id() > _maxId) _maxId = node.positive_id();
if (_firstPassDone) {
if (_firstPassDone || (!_config.addUntaggedNodes && node.tags().empty())) {
return;
}
_numNodes++;
}

// ____________________________________________________________________________
void osm2rdf::osm::CountHandler::relation(const osmium::Relation&) {
if (_firstPassDone) {
void osm2rdf::osm::CountHandler::relation(const osmium::Relation& rel) {
if (_firstPassDone || (!_config.addUntaggedRelations && rel.tags().empty())) {
return;
}
_numRelations++;
}

// ____________________________________________________________________________
void osm2rdf::osm::CountHandler::way(const osmium::Way&) {
if (_firstPassDone) {
void osm2rdf::osm::CountHandler::way(const osmium::Way& way) {
if (_firstPassDone || (!_config.addUntaggedWays && way.tags().empty())) {
return;
}
_numWays++;
}

// ____________________________________________________________________________
size_t osm2rdf::osm::CountHandler::numNodes() const {
return _numNodes;
}
size_t osm2rdf::osm::CountHandler::numNodes() const { return _numNodes; }

// ____________________________________________________________________________
size_t osm2rdf::osm::CountHandler::numRelations() const {
return _numRelations;
}

// ____________________________________________________________________________
size_t osm2rdf::osm::CountHandler::numWays() const {
return _numWays;
}
size_t osm2rdf::osm::CountHandler::numWays() const { return _numWays; }
21 changes: 20 additions & 1 deletion src/osm/OsmiumHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void osm2rdf::osm::OsmiumHandler<W>::handle() {
assembler_config.create_empty_areas = false;
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{
assembler_config};
osm2rdf::osm::CountHandler countHandler;
osm2rdf::osm::CountHandler countHandler(_config);

// read relations for areas
{
Expand Down Expand Up @@ -163,6 +163,11 @@ void osm2rdf::osm::OsmiumHandler<W>::handle() {
template <typename W>
void osm2rdf::osm::OsmiumHandler<W>::area(const osmium::Area& area) {
_areasSeen++;

if (!_config.addUntaggedAreas && area.tags().empty()) {
return;
}

try {
auto osmArea = osm2rdf::osm::Area(area);
#pragma omp task
Expand All @@ -187,6 +192,10 @@ template <typename W>
void osm2rdf::osm::OsmiumHandler<W>::node(const osmium::Node& node) {
_nodesSeen++;

if (!_config.addUntaggedNodes && node.tags().empty()) {
return;
}

try {
const auto& osmNode = osm2rdf::osm::Node(node);
#pragma omp task
Expand Down Expand Up @@ -224,6 +233,11 @@ template <typename W>
void osm2rdf::osm::OsmiumHandler<W>::relation(
const osmium::Relation& relation) {
_relationsSeen++;

if (!_config.addUntaggedRelations && relation.tags().empty()) {
return;
}

try {
// only task this away if we actually build the relation geometries,
// otherwise this just adds multithreading overhead for nothing
Expand Down Expand Up @@ -267,6 +281,11 @@ void osm2rdf::osm::OsmiumHandler<W>::relation(
template <typename W>
void osm2rdf::osm::OsmiumHandler<W>::way(const osmium::Way& way) {
_waysSeen++;

if (!_config.addUntaggedWays && way.tags().empty()) {
return;
}

try {
auto osmWay = osm2rdf::osm::Way(way);

Expand Down

0 comments on commit a032789

Please sign in to comment.