Skip to content

Commit

Permalink
Write triples for complete geo:sfContains and geo:sfIntersects (#56)
Browse files Browse the repository at this point in the history
* Materialize geo:sfContains and geo:sfIntersects

* add options --write-ogc-geo-triples (for writing the sfContains and sfIntersects relations) and --write-osm2rdf-geo-triples (for writing the "old-style" _area and _nonarea geometric triples). both with options "none", "reduced", "full". With "full", the full transitive closure w.r.t. contains of the respective relations is written. With "reduced", only the transitive reduction w.r.t. contains is written. With "none", no triples are written. Replaces the previous options --write-transitive-closure and --no-geometric-relations. By default, --write-ogc-geo-triples is set to "full".

---------

Co-authored-by: Hannah Bast <[email protected]>
Co-authored-by: Patrick Brosi <[email protected]>
  • Loading branch information
3 people authored Sep 7, 2023
1 parent bfc9a0e commit 5d75368
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 176 deletions.
10 changes: 8 additions & 2 deletions include/osm2rdf/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

namespace osm2rdf::config {

enum GeoTriplesMode {
none = 0,
reduced = 1,
full = 2
};

struct Config {
// Select what to do
std::string storeLocationsOnDisk;
Expand Down Expand Up @@ -97,8 +103,8 @@ struct Config {
double wktDeviation = 5;
uint16_t wktPrecision = 7;

// Transitive clouse
bool writeGeomRelTransClosure = false;
GeoTriplesMode ogcGeoTriplesMode = full;
GeoTriplesMode osm2rdfGeoTriplesMode = none;

// Output, empty for stdout
std::filesystem::path output;
Expand Down
30 changes: 15 additions & 15 deletions include/osm2rdf/config/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,21 @@ const static inline std::string NO_FACTS_OPTION_SHORT = "";
const static inline std::string NO_FACTS_OPTION_LONG = "no-facts";
const static inline std::string NO_FACTS_OPTION_HELP = "Do not dump facts";

const static inline std::string NO_GEOM_RELATIONS_INFO =
"Not dumping geometric relations";
const static inline std::string NO_GEOM_RELATIONS_OPTION_SHORT = "";
const static inline std::string NO_GEOM_RELATIONS_OPTION_LONG =
"no-geometric-relations";
const static inline std::string NO_GEOM_RELATIONS_OPTION_HELP =
"Do not dump geometric relations";

const static inline std::string WRITE_GEOM_REl_TRANS_CLOSURE_INFO =
"Not dumping geometric relations";
const static inline std::string WRITE_GEOM_REl_TRANS_CLOSURE_OPTION_SHORT = "";
const static inline std::string WRITE_GEOM_REl_TRANS_CLOSURE_OPTION_LONG =
"write-transitive-closure";
const static inline std::string WRITE_GEOM_REl_TRANS_CLOSURE_OPTION_HELP =
"Write the transitive closure of all geometric relations";
const static inline std::string OSM2RDF_GEO_TRIPLES_INFO =
"Writing mode of osm2rdf-style geometric triples";
const static inline std::string OSM2RDF_GEO_TRIPLES_OPTION_SHORT = "";
const static inline std::string OSM2RDF_GEO_TRIPLES_OPTION_LONG =
"write-osm2rdf-geo-triples";
const static inline std::string OSM2RDF_GEO_TRIPLES_OPTION_HELP =
"Writing of osm2rdf-style geometric triples, either 'full', 'reduced', or 'none'";

const static inline std::string OGC_GEO_TRIPLES_INFO =
"Writing mode of OGC-style geometric triples";
const static inline std::string OGC_GEO_TRIPLES_OPTION_SHORT = "";
const static inline std::string OGC_GEO_TRIPLES_OPTION_LONG =
"write-ogc-geo-triples";
const static inline std::string OGC_GEO_TRIPLES_OPTION_HELP =
"Writing of OGC-style geometric triples, either 'full', 'reduced', or 'none'";

const static inline std::string NO_AREA_OPTION_SHORT = "";
const static inline std::string NO_AREA_OPTION_LONG = "no-areas";
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 @@ -43,11 +43,16 @@ inline std::string IRI__GEOSPARQL__AS_WKT;
inline std::string IRI__GEOSPARQL__HAS_GEOMETRY;
inline std::string IRI__GEOSPARQL__WKT_LITERAL;

inline std::string IRI__OPENGIS_CONTAINS;
inline std::string IRI__OSM2RDF_CONTAINS_NON_AREA;
inline std::string IRI__OSM2RDF_CONTAINS_AREA;
inline std::string IRI__OPENGIS_INTERSECTS;
inline std::string IRI__OSM2RDF_INTERSECTS_NON_AREA;
inline std::string IRI__OSM2RDF_INTERSECTS_AREA;

inline std::string IRI__OSM2RDF_CONTAINS;
inline std::string IRI__OSM2RDF_INTERSECTS;

inline std::string IRI__OSM2RDF_GEOM__CONVEX_HULL;
inline std::string IRI__OSM2RDF_GEOM__ENVELOPE;
inline std::string IRI__OSM2RDF_GEOM__OBB;
Expand Down
140 changes: 91 additions & 49 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
}
if (addAreaOrientedBoundingBox) {
oss << "\n"
<< prefix << osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_INFO;
<< prefix
<< osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_INFO;
}
if (addAreaEnvelopeRatio) {
oss << "\n"
Expand All @@ -87,7 +88,8 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
}
if (addNodeOrientedBoundingBox) {
oss << "\n"
<< prefix << osm2rdf::config::constants::ADD_NODE_ORIENTED_BOUNDING_BOX_INFO;
<< prefix
<< osm2rdf::config::constants::ADD_NODE_ORIENTED_BOUNDING_BOX_INFO;
}
}
if (noRelationFacts) {
Expand All @@ -101,15 +103,18 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
}
if (addRelationConvexHull) {
oss << "\n"
<< prefix << osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_INFO;
<< prefix
<< osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_INFO;
}
if (addRelationEnvelope) {
oss << "\n"
<< prefix << osm2rdf::config::constants::ADD_RELATION_ENVELOPE_INFO;
}
if (addRelationOrientedBoundingBox) {
oss << "\n"
<< prefix << osm2rdf::config::constants::ADD_RELATION_ORIENTED_BOUNDING_BOX_INFO;
<< prefix
<< osm2rdf::config::constants::
ADD_RELATION_ORIENTED_BOUNDING_BOX_INFO;
}
}
if (noWayFacts) {
Expand All @@ -125,7 +130,8 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
}
if (addWayOrientedBoundingBox) {
oss << "\n"
<< prefix << osm2rdf::config::constants::ADD_WAY_ORIENTED_BOUNDING_BOX_INFO;
<< prefix
<< osm2rdf::config::constants::ADD_WAY_ORIENTED_BOUNDING_BOX_INFO;
}
if (addWayMetadata) {
oss << "\n"
Expand Down Expand Up @@ -172,9 +178,16 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
}
}
oss << "\n" << prefix << osm2rdf::config::constants::SECTION_CONTAINS;
if (noGeometricRelations) {
oss << "\n" << prefix << osm2rdf::config::constants::NO_GEOM_RELATIONS_INFO;
} else {
std::string modeStrings[3] = {"none", "full", "reduced"};
oss << "\n"
<< prefix << osm2rdf::config::constants::OSM2RDF_GEO_TRIPLES_INFO << ": "
<< (modeStrings[osm2rdfGeoTriplesMode]);

oss << "\n"
<< prefix << osm2rdf::config::constants::OGC_GEO_TRIPLES_INFO << ": "
<< (modeStrings[ogcGeoTriplesMode]);

if (ogcGeoTriplesMode || osm2rdfGeoTriplesMode) {
if (adminRelationsOnly) {
oss << "\n"
<< prefix << osm2rdf::config::constants::ADMIN_RELATIONS_ONLY_INFO;
Expand All @@ -196,11 +209,6 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
<< prefix << osm2rdf::config::constants::SIMPLIFY_GEOMETRIES_INFO
<< std::to_string(simplifyGeometries);
}
if (writeGeomRelTransClosure) {
oss << "\n"
<< prefix
<< osm2rdf::config::constants::WRITE_GEOM_REl_TRANS_CLOSURE_INFO;
}
}
oss << "\n" << prefix << osm2rdf::config::constants::SECTION_MISCELLANEOUS;
if (writeDAGDotFiles) {
Expand Down Expand Up @@ -282,11 +290,6 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
osm2rdf::config::constants::NO_WAY_FACTS_OPTION_LONG,
osm2rdf::config::constants::NO_WAY_FACTS_OPTION_HELP);

auto noGeometricRelationsOp =
parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::NO_GEOM_RELATIONS_OPTION_SHORT,
osm2rdf::config::constants::NO_GEOM_RELATIONS_OPTION_LONG,
osm2rdf::config::constants::NO_GEOM_RELATIONS_OPTION_HELP);
auto noAreaGeometricRelationsOp =
parser.add<popl::Switch, popl::Attribute::expert>(
osm2rdf::config::constants::NO_AREA_GEOM_RELATIONS_OPTION_SHORT,
Expand All @@ -302,24 +305,31 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
osm2rdf::config::constants::NO_WAY_GEOM_RELATIONS_OPTION_SHORT,
osm2rdf::config::constants::NO_WAY_GEOM_RELATIONS_OPTION_LONG,
osm2rdf::config::constants::NO_WAY_GEOM_RELATIONS_OPTION_HELP);
auto writeGeomRelTransClosureOp =
parser.add<popl::Switch, popl::Attribute::expert>(
osm2rdf::config::constants::WRITE_GEOM_REl_TRANS_CLOSURE_OPTION_SHORT,
osm2rdf::config::constants::WRITE_GEOM_REl_TRANS_CLOSURE_OPTION_LONG,
osm2rdf::config::constants::WRITE_GEOM_REl_TRANS_CLOSURE_OPTION_HELP);

auto addAreaConvexHullOp = parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::ADD_AREA_CONVEX_HULL_OPTION_SHORT,
osm2rdf::config::constants::ADD_AREA_CONVEX_HULL_OPTION_LONG,
osm2rdf::config::constants::ADD_AREA_CONVEX_HULL_OPTION_HELP);
auto addAreaEnvelopeOp = parser.add<popl::Switch>(
osm2rdf::config::constants::ADD_AREA_ENVELOPE_OPTION_SHORT,
osm2rdf::config::constants::ADD_AREA_ENVELOPE_OPTION_LONG,
osm2rdf::config::constants::ADD_AREA_ENVELOPE_OPTION_HELP);
auto addAreaOrientedBoundingBoxOp = parser.add<popl::Switch>(
osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_SHORT,
osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_LONG,
osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_HELP);
auto ogcGeoTriplesModeOp =
parser.add<popl::Value<std::string>, popl::Attribute::advanced>(
osm2rdf::config::constants::OGC_GEO_TRIPLES_OPTION_SHORT,
osm2rdf::config::constants::OGC_GEO_TRIPLES_OPTION_LONG,
osm2rdf::config::constants::OGC_GEO_TRIPLES_OPTION_HELP, "full");

auto osm2rdfGeoTriplesModeOp =
parser.add<popl::Value<std::string>, popl::Attribute::advanced>(
osm2rdf::config::constants::OSM2RDF_GEO_TRIPLES_OPTION_SHORT,
osm2rdf::config::constants::OSM2RDF_GEO_TRIPLES_OPTION_LONG,
osm2rdf::config::constants::OSM2RDF_GEO_TRIPLES_OPTION_HELP, "none");

auto addAreaConvexHullOp =
parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::ADD_AREA_CONVEX_HULL_OPTION_SHORT,
osm2rdf::config::constants::ADD_AREA_CONVEX_HULL_OPTION_LONG,
osm2rdf::config::constants::ADD_AREA_CONVEX_HULL_OPTION_HELP);
auto addAreaEnvelopeOp = parser.add<popl::Switch>(
osm2rdf::config::constants::ADD_AREA_ENVELOPE_OPTION_SHORT,
osm2rdf::config::constants::ADD_AREA_ENVELOPE_OPTION_LONG,
osm2rdf::config::constants::ADD_AREA_ENVELOPE_OPTION_HELP);
auto addAreaOrientedBoundingBoxOp = parser.add<popl::Switch>(
osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_SHORT,
osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_LONG,
osm2rdf::config::constants::ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_HELP);
auto addAreaEnvelopeRatioOp =
parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::ADD_AREA_ENVELOPE_RATIO_OPTION_SHORT,
Expand All @@ -330,23 +340,28 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
osm2rdf::config::constants::ADD_RELATION_BORDER_MEMBERS_OPTION_LONG,
osm2rdf::config::constants::ADD_RELATION_BORDER_MEMBERS_OPTION_HELP);
#if BOOST_VERSION >= 107800
auto addRelationConvexHullOp = parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_OPTION_SHORT,
osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_OPTION_LONG,
osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_OPTION_HELP);
auto addRelationConvexHullOp =
parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_OPTION_SHORT,
osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_OPTION_LONG,
osm2rdf::config::constants::ADD_RELATION_CONVEX_HULL_OPTION_HELP);
auto addRelationEnvelopeOp = parser.add<popl::Switch>(
osm2rdf::config::constants::ADD_RELATION_ENVELOPE_OPTION_SHORT,
osm2rdf::config::constants::ADD_RELATION_ENVELOPE_OPTION_LONG,
osm2rdf::config::constants::ADD_RELATION_ENVELOPE_OPTION_HELP);
auto addRelationOrientedBoundingBoxOp = parser.add<popl::Switch>(
osm2rdf::config::constants::ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_SHORT,
osm2rdf::config::constants::ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_LONG,
osm2rdf::config::constants::ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_HELP);
osm2rdf::config::constants::
ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_SHORT,
osm2rdf::config::constants::
ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_LONG,
osm2rdf::config::constants::
ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_HELP);
#endif // BOOST_VERSION >= 107800
auto addNodeConvexHullOp = parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::ADD_NODE_CONVEX_HULL_OPTION_SHORT,
osm2rdf::config::constants::ADD_NODE_CONVEX_HULL_OPTION_LONG,
osm2rdf::config::constants::ADD_NODE_CONVEX_HULL_OPTION_HELP);
auto addNodeConvexHullOp =
parser.add<popl::Switch, popl::Attribute::advanced>(
osm2rdf::config::constants::ADD_NODE_CONVEX_HULL_OPTION_SHORT,
osm2rdf::config::constants::ADD_NODE_CONVEX_HULL_OPTION_LONG,
osm2rdf::config::constants::ADD_NODE_CONVEX_HULL_OPTION_HELP);
auto addNodeEnvelopeOp = parser.add<popl::Switch>(
osm2rdf::config::constants::ADD_NODE_ENVELOPE_OPTION_SHORT,
osm2rdf::config::constants::ADD_NODE_ENVELOPE_OPTION_LONG,
Expand Down Expand Up @@ -498,7 +513,6 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {

// Skip passes
noFacts = noFactsOp->is_set();
noGeometricRelations = noGeometricRelationsOp->is_set();

if (storeLocationsOnDiskOp->is_set()) {
storeLocationsOnDisk = storeLocationsOnDiskOp->value();
Expand All @@ -514,7 +528,35 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
noNodeGeometricRelations = noNodeGeometricRelationsOp->is_set();
noWayGeometricRelations = noWayGeometricRelationsOp->is_set();

writeGeomRelTransClosure = writeGeomRelTransClosureOp->is_set();
if (ogcGeoTriplesModeOp->is_set()) {
if (ogcGeoTriplesModeOp->value() == "none") {
ogcGeoTriplesMode = none;
} else if (ogcGeoTriplesModeOp->value() == "reduced") {
ogcGeoTriplesMode = reduced;
} else if (ogcGeoTriplesModeOp->value() == "full") {
ogcGeoTriplesMode = full;
} else {
throw popl::invalid_option(
ogcGeoTriplesModeOp.get(),
popl::invalid_option::Error::invalid_argument,
popl::OptionName::long_name, ogcGeoTriplesModeOp->value(), "");
}
}

if (osm2rdfGeoTriplesModeOp->is_set()) {
if (osm2rdfGeoTriplesModeOp->value() == "none") {
osm2rdfGeoTriplesMode = none;
} else if (osm2rdfGeoTriplesModeOp->value() == "reduced") {
osm2rdfGeoTriplesMode = reduced;
} else if (osm2rdfGeoTriplesModeOp->value() == "full") {
osm2rdfGeoTriplesMode = full;
} else {
throw popl::invalid_option(
osm2rdfGeoTriplesModeOp.get(),
popl::invalid_option::Error::invalid_argument,
popl::OptionName::long_name, osm2rdfGeoTriplesModeOp->value(), "");
}
}

noAreaFacts |= noAreasOp->is_set();
noAreaGeometricRelations |= noAreasOp->is_set();
Expand Down
Loading

0 comments on commit 5d75368

Please sign in to comment.