Skip to content

Commit

Permalink
Prepare basic infrastructure to handle Changeset objects
Browse files Browse the repository at this point in the history
  • Loading branch information
lehmann-4178656ch committed Oct 18, 2024
1 parent b5a6e92 commit 8345f3c
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 19 deletions.
1 change: 1 addition & 0 deletions include/osm2rdf/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct Config {

bool noFacts = false;
bool noAreaFacts = false;
bool noChangesetFacts = false;
bool noNodeFacts = false;
bool noRelationFacts = false;
bool noWayFacts = false;
Expand Down
9 changes: 9 additions & 0 deletions include/osm2rdf/config/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ const static inline std::string NO_AREA_GEOM_RELATIONS_OPTION_LONG =
const static inline std::string NO_AREA_GEOM_RELATIONS_OPTION_HELP =
"Do not dump area geometric relations";

const static inline std::string NO_CHANGESET_OPTION_SHORT = "";
const static inline std::string NO_CHANGESET_OPTION_LONG = "no-changesets";
const static inline std::string NO_CHANGESET_OPTION_HELP = "Ignore changesets";
const static inline std::string NO_CHANGESET_FACTS_INFO = "Ignoring changeset facts";
const static inline std::string NO_CHANGESET_FACTS_OPTION_SHORT = "";
const static inline std::string NO_CHANGESET_FACTS_OPTION_LONG = "no-changeset-facts";
const static inline std::string NO_CHANGESET_FACTS_OPTION_HELP =
"Do not dump changeset facts";

const static inline std::string NO_NODE_OPTION_SHORT = "";
const static inline std::string NO_NODE_OPTION_LONG = "no-nodes";
const static inline std::string NO_NODE_OPTION_HELP = "Ignore nodes";
Expand Down
39 changes: 39 additions & 0 deletions include/osm2rdf/osm/Changeset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024, University of Freiburg
// Authors: Axel Lehmann <[email protected]>.

// This file is part of osm2rdf.
//
// osm2rdf is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// osm2rdf is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with osm2rdf. If not, see <https://www.gnu.org/licenses/>.

#ifndef OSM2RDF_OSM_CHANGESET_H_
#define OSM2RDF_OSM_CHANGESET_H_

#include "osmium/osm/changeset.hpp"

namespace osm2rdf::osm {

class Changeset {
public:
typedef uint32_t id_t;
Changeset();
explicit Changeset(const osmium::Changeset& changeset);
[[nodiscard]] id_t id() const noexcept;

protected:
id_t _id;
};

} // namespace osm2rdf::osm

#endif // OSM2RDF_OSM_CHANGESET_H_
9 changes: 6 additions & 3 deletions include/osm2rdf/osm/CountHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ namespace osm2rdf::osm {

class CountHandler : public osmium::handler::Handler {
public:
void changeset(const osmium::Changeset& changeset);
void node(const osmium::Node& node);
void relation(const osmium::Relation& relation);
void way(const osmium::Way& way);
void prepare_for_lookup();

size_t numNodes() const;
size_t numRelations() const;
size_t numWays() const;
[[nodiscard]] size_t numChangesets() const;
[[nodiscard]] size_t numNodes() const;
[[nodiscard]] size_t numRelations() const;
[[nodiscard]] size_t numWays() const;

protected:
size_t _numChangesets = 0;
size_t _numNodes = 0;
size_t _numRelations = 0;
size_t _numWays = 0;
Expand Down
8 changes: 8 additions & 0 deletions include/osm2rdf/osm/FactHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
#include "osm2rdf/config/Config.h"
#include "osm2rdf/ttl/Writer.h"
#include "util/geo/Geo.h"
#include "osm2rdf/osm/Area.h"
#include "osm2rdf/osm/Box.h"
#include "osm2rdf/osm/Changeset.h"
#include "osm2rdf/osm/Node.h"
#include "osm2rdf/osm/Relation.h"
#include "osm2rdf/osm/Tag.h"
#include "osm2rdf/osm/TagList.h"

namespace osm2rdf::osm {

Expand All @@ -44,6 +51,7 @@ class FactHandler {
osm2rdf::ttl::Writer<W>* writer);
// Add data
void area(const osm2rdf::osm::Area& area);
void changeset(const osm2rdf::osm::Changeset& changeset);
void node(const osm2rdf::osm::Node& node);
void relation(const osm2rdf::osm::Relation& relation);
void way(const osm2rdf::osm::Way& way);
Expand Down
6 changes: 6 additions & 0 deletions include/osm2rdf/osm/GeometryHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#include "gtest/gtest_prod.h"
#include "osm2rdf/config/Config.h"
#include "osm2rdf/osm/Area.h"
#include "osm2rdf/osm/Box.h"
#include "osm2rdf/osm/Node.h"
#include "osm2rdf/osm/Relation.h"
#include "osm2rdf/osm/Tag.h"
#include "osm2rdf/osm/TagList.h"
#include "osm2rdf/osm/Way.h"
#include "osm2rdf/ttl/Writer.h"
#include "osm2rdf/util/CacheFile.h"
#include "osm2rdf/util/DirectedGraph.h"
Expand Down
5 changes: 5 additions & 0 deletions include/osm2rdf/osm/OsmiumHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ class OsmiumHandler : public osmium::handler::Handler {
osm2rdf::ttl::Writer<W>* writer);
void handle();
void area(const osmium::Area& area);
void changeset(const osmium::Changeset& changeset);
void node(const osmium::Node& node);
void relation(const osmium::Relation& relation);
void way(const osmium::Way& way);

[[nodiscard]] size_t areasSeen() const;
[[nodiscard]] size_t areasDumped() const;
[[nodiscard]] size_t areaGeometriesHandled() const;
[[nodiscard]] size_t changesetsSeen() const;
[[nodiscard]] size_t changesetsDumped() const;
[[nodiscard]] size_t nodesSeen() const;
[[nodiscard]] size_t nodesDumped() const;
[[nodiscard]] size_t nodeGeometriesHandled() const;
Expand All @@ -66,6 +69,8 @@ class OsmiumHandler : public osmium::handler::Handler {
size_t _areasSeen = 0;
size_t _areasDumped = 0;
size_t _areaGeometriesHandled = 0;
size_t _changesetsSeen = 0;
size_t _changesetsDumped = 0;
size_t _nodesSeen = 0;
size_t _nodesDumped = 0;
size_t _nodeGeometriesHandled = 0;
Expand Down
5 changes: 5 additions & 0 deletions include/osm2rdf/ttl/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ namespace osm2rdf::ttl::constants {

// Real constants
const static inline std::string NAMESPACE__GEOSPARQL = "geo";
const static inline std::string NAMESPACE__OHM_CHANGESET = "ohmchangeset";
const static inline std::string NAMESPACE__OHM_NODE = "ohmnode";
const static inline std::string NAMESPACE__OHM_RELATION = "ohmrel";
const static inline std::string NAMESPACE__OHM_WAY = "ohmway";
const static inline std::string NAMESPACE__OHM = "ohm";
const static inline std::string NAMESPACE__OPENGIS = "ogc";
const static inline std::string NAMESPACE__OSM_CHANGESET = "osmchangeset";
const static inline std::string NAMESPACE__OSM_NODE = "osmnode";
const static inline std::string NAMESPACE__OSM_RELATION = "osmrel";
const static inline std::string NAMESPACE__OSM_TAG = "osmkey";
Expand Down Expand Up @@ -77,6 +79,7 @@ inline std::string IRI__OSMWAY_NEXT_NODE_DISTANCE;
inline std::string IRI__OSMWAY_NODE;
inline std::string IRI__OSMWAY_NODE_COUNT;
inline std::string IRI__OSMWAY_UNIQUE_NODE_COUNT;
inline std::string IRI__OSM_CHANGESET;
inline std::string IRI__OSM_NODE;
inline std::string IRI__OSM_RELATION;
inline std::string IRI__OSM_TAG;
Expand All @@ -98,6 +101,8 @@ inline std::string LITERAL__YES;

// Arrays holding values depending on the used dataset
const static inline std::vector<std::string> DATASET_ID = {"osm", "ohm"};
const static inline std::vector<std::string> CHANGESET_NAMESPACE = {
NAMESPACE__OSM_CHANGESET, NAMESPACE__OHM_CHANGESET};
const static inline std::vector<std::string> NODE_NAMESPACE = {
NAMESPACE__OSM_NODE, NAMESPACE__OHM_NODE};
const static inline std::vector<std::string> RELATION_NAMESPACE = {
Expand Down
1 change: 0 additions & 1 deletion include/osm2rdf/ttl/Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class Writer {
uint64_t* _lineCount;
// Number of parts.
std::size_t _numOuts;

};
} // namespace osm2rdf::ttl

Expand Down
13 changes: 13 additions & 0 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
if (noAreaFacts) {
oss << "\n" << prefix << osm2rdf::config::constants::NO_AREA_FACTS_INFO;
}
if (noChangesetFacts) {
oss << "\n" << prefix << osm2rdf::config::constants::NO_CHANGESET_FACTS_INFO;
}
if (noNodeFacts) {
oss << "\n" << prefix << osm2rdf::config::constants::NO_NODE_FACTS_INFO;
}
Expand Down Expand Up @@ -192,6 +195,10 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
osm2rdf::config::constants::NO_AREA_OPTION_SHORT,
osm2rdf::config::constants::NO_AREA_OPTION_LONG,
osm2rdf::config::constants::NO_AREA_OPTION_HELP);
auto noChangesetsOp = parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::NO_CHANGESET_OPTION_SHORT,
osm2rdf::config::constants::NO_CHANGESET_OPTION_LONG,
osm2rdf::config::constants::NO_CHANGESET_OPTION_HELP);
auto noNodesOp = parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::NO_NODE_OPTION_SHORT,
osm2rdf::config::constants::NO_NODE_OPTION_LONG,
Expand All @@ -213,6 +220,10 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
osm2rdf::config::constants::NO_AREA_FACTS_OPTION_SHORT,
osm2rdf::config::constants::NO_AREA_FACTS_OPTION_LONG,
osm2rdf::config::constants::NO_AREA_FACTS_OPTION_HELP);
auto noChangesetFactsOp = parser.add<popl::Switch, popl::Attribute::expert>(
osm2rdf::config::constants::NO_CHANGESET_FACTS_OPTION_SHORT,
osm2rdf::config::constants::NO_CHANGESET_FACTS_OPTION_LONG,
osm2rdf::config::constants::NO_CHANGESET_FACTS_OPTION_HELP);
auto noNodeFactsOp = parser.add<popl::Switch, popl::Attribute::expert>(
osm2rdf::config::constants::NO_NODE_FACTS_OPTION_SHORT,
osm2rdf::config::constants::NO_NODE_FACTS_OPTION_LONG,
Expand Down Expand Up @@ -392,6 +403,7 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {

// Select types to dump
noAreaFacts = noAreaFactsOp->is_set();
noChangesetFacts = noChangesetFactsOp->is_set();
noNodeFacts = noNodeFactsOp->is_set();
noRelationFacts = noRelationFactsOp->is_set();
noWayFacts = noWayFactsOp->is_set();
Expand All @@ -418,6 +430,7 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {

noAreaFacts |= noAreasOp->is_set();
noAreaGeometricRelations |= noAreasOp->is_set();
noChangesetFacts |= noChangesetsOp->is_set();
noNodeFacts |= noNodesOp->is_set();
noNodeGeometricRelations |= noNodesOp->is_set();
noRelationFacts |= noRelationsOp->is_set();
Expand Down
39 changes: 39 additions & 0 deletions src/osm/Changeset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024, University of Freiburg
// Authors: Axel Lehmann <[email protected]>

// This file is part of osm2rdf.
//
// osm2rdf is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// osm2rdf is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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/Changeset.h"

#include <iostream>
#include <limits>

#include "osmium/osm/changeset.hpp"

// ____________________________________________________________________________
osm2rdf::osm::Changeset::Changeset() {
_id = std::numeric_limits<osm2rdf::osm::Changeset::id_t>::max();
}
// ____________________________________________________________________________
osm2rdf::osm::Changeset::Changeset(const osmium::Changeset& changeset)
: Changeset() {
_id = changeset.id();
}

// ____________________________________________________________________________
osm2rdf::osm::Changeset::id_t osm2rdf::osm::Changeset::id() const noexcept {
return _id;
}
21 changes: 15 additions & 6 deletions src/osm/CountHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
#include <iostream>

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

// ----------------------------------------------------------------------------
void osm2rdf::osm::CountHandler::changeset(
const osmium::Changeset& /*unused*/) {
if (_firstPassDone) {
return;
}
_numChangesets++;
}
// ____________________________________________________________________________
void osm2rdf::osm::CountHandler::node(const osmium::Node& node){
if (_firstPassDone || node.tags().empty()) {
Expand All @@ -49,11 +55,14 @@ void osm2rdf::osm::CountHandler::way(const osmium::Way& way) {
_numWays++;
}

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

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

// ____________________________________________________________________________
size_t osm2rdf::osm::CountHandler::numRelations() const {
return _numRelations;
Expand Down
10 changes: 10 additions & 0 deletions src/osm/FactHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ using osm2rdf::ttl::constants::IRI__OSM2RDF_GEOM__OBB;
using osm2rdf::ttl::constants::IRI__OSM2RDF_MEMBER__ID;
using osm2rdf::ttl::constants::IRI__OSM2RDF_MEMBER__POS;
using osm2rdf::ttl::constants::IRI__OSM2RDF_MEMBER__ROLE;
using osm2rdf::ttl::constants::IRI__OSM_CHANGESET;
using osm2rdf::ttl::constants::IRI__OSM_NODE;
using osm2rdf::ttl::constants::IRI__OSM_RELATION;
using osm2rdf::ttl::constants::IRI__OSM_TAG;
Expand Down Expand Up @@ -75,6 +76,7 @@ using osm2rdf::ttl::constants::NAMESPACE__OSM_RELATION;
using osm2rdf::ttl::constants::NAMESPACE__OSM_TAG;
using osm2rdf::ttl::constants::NAMESPACE__OSM_WAY;
using osm2rdf::ttl::constants::NAMESPACE__WIKIDATA_ENTITY;
using osm2rdf::ttl::constants::CHANGESET_NAMESPACE;
using osm2rdf::ttl::constants::NODE_NAMESPACE;
using osm2rdf::ttl::constants::RELATION_NAMESPACE;
using osm2rdf::ttl::constants::WAY_NAMESPACE;
Expand Down Expand Up @@ -122,6 +124,14 @@ void osm2rdf::osm::FactHandler<W>::area(const osm2rdf::osm::Area& area) {
_writer->generateLiteralUnsafe(tmp.str(), "^^" + IRI__XSD_DOUBLE));
}

// ____________________________________________________________________________
template <typename W>
void osm2rdf::osm::FactHandler<W>::changeset(const osm2rdf::osm::Changeset& changeset) {
const std::string& subj =
_writer->generateIRI(CHANGESET_NAMESPACE[_config.sourceDataset], changeset.id());
_writer->writeTriple(subj, IRI__RDF_TYPE, IRI__OSM_CHANGESET);
}

// ____________________________________________________________________________
template <typename W>
void osm2rdf::osm::FactHandler<W>::node(const osm2rdf::osm::Node& node) {
Expand Down
Loading

0 comments on commit 8345f3c

Please sign in to comment.