Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic GeoJSON output #52

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/osm2rdf/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ struct Config {
bool writeRDFStatistics = false;
std::filesystem::path rdfStatisticsPath;

// Output modifiers
uint16_t simplifyWKT = 250;
double wktDeviation = 5;
uint16_t wktPrecision = 7;
// Geometry output modifiers
uint16_t geometriesDumpMinNumPointsForSimplification = 250;
double geometriesDumpDeviation = 5;
uint16_t geometriesDumpPrecision = 7;

// Transitive clouse
// Transitive closure
bool writeGeomRelTransClosure = false;

// Output, empty for stdout
Expand Down
66 changes: 37 additions & 29 deletions include/osm2rdf/config/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ const static inline std::string ADD_AREA_ENVELOPE_RATIO_OPTION_HELP =

const static inline std::string ADD_AREA_ORIENTED_BOUNDING_BOX_INFO =
"Adding area oriented-bounding-boxes";
const static inline std::string ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_SHORT = "";
const static inline std::string ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_SHORT =
"";
const static inline std::string ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_LONG =
"add-area-oriented-bounding-box";
const static inline std::string ADD_AREA_ORIENTED_BOUNDING_BOX_OPTION_HELP =
Expand Down Expand Up @@ -227,7 +228,8 @@ const static inline std::string ADD_NODE_ENVELOPE_OPTION_HELP =

const static inline std::string ADD_NODE_ORIENTED_BOUNDING_BOX_INFO =
"Adding node oriented-bounding-boxes";
const static inline std::string ADD_NODE_ORIENTED_BOUNDING_BOX_OPTION_SHORT = "";
const static inline std::string ADD_NODE_ORIENTED_BOUNDING_BOX_OPTION_SHORT =
"";
const static inline std::string ADD_NODE_ORIENTED_BOUNDING_BOX_OPTION_LONG =
"add-node-oriented-bounding-box";
const static inline std::string ADD_NODE_ORIENTED_BOUNDING_BOX_OPTION_HELP =
Expand All @@ -249,7 +251,8 @@ const static inline std::string ADD_RELATION_CONVEX_HULL_OPTION_LONG =
const static inline std::string ADD_RELATION_CONVEX_HULL_OPTION_HELP =
"Add convex hull to relations";

const static inline std::string ADD_RELATION_ENVELOPE_INFO = "Adding relation envelopes";
const static inline std::string ADD_RELATION_ENVELOPE_INFO =
"Adding relation envelopes";
const static inline std::string ADD_RELATION_ENVELOPE_OPTION_SHORT = "";
const static inline std::string ADD_RELATION_ENVELOPE_OPTION_LONG =
"add-relation-envelope";
Expand All @@ -258,7 +261,8 @@ const static inline std::string ADD_RELATION_ENVELOPE_OPTION_HELP =

const static inline std::string ADD_RELATION_ORIENTED_BOUNDING_BOX_INFO =
"Adding relation oriented-bounding-boxes";
const static inline std::string ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_SHORT = "";
const static inline std::string
ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_SHORT = "";
const static inline std::string ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_LONG =
"add-relation-oriented-bounding-box";
const static inline std::string ADD_RELATION_ORIENTED_BOUNDING_BOX_OPTION_HELP =
Expand Down Expand Up @@ -341,7 +345,7 @@ const static inline std::string SIMPLIFY_GEOMETRIES_OPTION_SHORT = "";
const static inline std::string SIMPLIFY_GEOMETRIES_OPTION_LONG =
"simplify-geometries";
const static inline std::string SIMPLIFY_GEOMETRIES_OPTION_HELP =
"Factor for geometry simplifaction, 0 to disable; will be multiplied with "
"Factor for geometry simplification, 0 to disable; will be multiplied with "
"the geometry "
"perimeter or length. This only affects "
"relationship calculations and not the geometry dump";
Expand Down Expand Up @@ -369,26 +373,29 @@ const static inline std::string DONT_USE_INNER_OUTER_GEOMETRIES_OPTION_HELP =

const static inline std::string APPROX_SPATIAL_REL_INFO =
"Approximate spatial relations using inner/outer simplified geometries.";
const static inline std::string APPROX_SPATIAL_REL_OPTION_SHORT =
"";
const static inline std::string APPROX_SPATIAL_REL_OPTION_SHORT = "";
const static inline std::string APPROX_SPATIAL_REL_OPTION_LONG =
"approximate-spatial-relations";
const static inline std::string APPROX_SPATIAL_REL_OPTION_HELP = "Use "
"simplified inner/outer geometries for approximate calcuation of spatial "
"relations";

const static inline std::string SIMPLIFY_WKT_INFO = "Simplifying WKT";
const static inline std::string SIMPLIFY_WKT_OPTION_SHORT = "s";
const static inline std::string SIMPLIFY_WKT_OPTION_LONG = "simplify-wkt";
const static inline std::string SIMPLIFY_WKT_OPTION_HELP =
"Simplify WKT-Geometries over this number of nodes, 0 to disable";

const static inline std::string SIMPLIFY_WKT_DEVIATION_INFO =
"Simplifying wkt geometries with factor: ";
const static inline std::string SIMPLIFY_WKT_DEVIATION_OPTION_SHORT = "";
const static inline std::string SIMPLIFY_WKT_DEVIATION_OPTION_LONG =
"simplify-wkt-deviation";
const static inline std::string SIMPLIFY_WKT_DEVIATION_OPTION_HELP =
const static inline std::string APPROX_SPATIAL_REL_OPTION_HELP =
"Use "
"simplified inner/outer geometries for approximate calcuation of spatial "
"relations";

const static inline std::string SIMPLIFY_GEOMETRIES_DUMP_INFO =
"Simplifying output geometries";
const static inline std::string SIMPLIFY_GEOMETRIES_DUMP_OPTION_SHORT = "s";
const static inline std::string SIMPLIFY_GEOMETRIES_DUMP_OPTION_LONG =
"simplify-geometries-dump";
const static inline std::string SIMPLIFY_GEOMETRIES_DUMP_OPTION_HELP =
"Simplify dumped geometries with more than this number of nodes, 0 to "
"disable";

const static inline std::string GEOMETRIES_DUMP_DEVIATION_INFO =
"Simplifying dumped geometries with factor: ";
const static inline std::string GEOMETRIES_DUMP_DEVIATION_OPTION_SHORT = "";
const static inline std::string GEOMETRIES_DUMP_DEVIATION_OPTION_LONG =
"geometries-dump-deviation";
const static inline std::string GEOMETRIES_DUMP_DEVIATION_OPTION_HELP =
"Same effect as simplify-geometries but for the simplification of dumped "
"geometries";

Expand All @@ -406,12 +413,13 @@ const static inline std::string SEMICOLON_TAG_KEYS_OPTION_LONG =
"split-tag-key-by-semicolon";
const static inline std::string SEMICOLON_TAG_KEYS_OPTION_HELP = "";

const static inline std::string WKT_PRECISION_INFO =
"Dumping WKT with precision: ";
const static inline std::string WKT_PRECISION_OPTION_SHORT = "";
const static inline std::string WKT_PRECISION_OPTION_LONG = "wkt-precision";
const static inline std::string WKT_PRECISION_OPTION_HELP =
"Precision (number of decimal digits) for WKT coordinates";
const static inline std::string GEOMETRIES_DUMP_PRECISION_INFO =
"Dumping geometries with precision: ";
const static inline std::string GEOMETRIES_DUMP_PRECISION_OPTION_SHORT = "";
const static inline std::string GEOMETRIES_DUMP_PRECISION_OPTION_LONG =
"geometries-dump-precision";
const static inline std::string GEOMETRIES_DUMP_PRECISION_OPTION_HELP =
"Precision (number of decimal digits) for dumped geometry coordinates";

const static inline std::string WRITE_DAG_DOT_FILES_INFO =
"Storing DAG states as .dot files";
Expand Down
34 changes: 23 additions & 11 deletions include/osm2rdf/osm/FactHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,32 @@ class FactHandler {
void relation(const osm2rdf::osm::Relation& relation);
void way(const osm2rdf::osm::Way& way);

protected:
template <typename G>
void writeBoostGeometry(const std::string& s, const std::string& p,
const G& g);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWay);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWaySimplify1);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWaySimplify2);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWaySimplify3);
G simplifyGeometry(const G& g);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktWaySimplify1);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktWaySimplify2);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktWaySimplify3);

protected:
template <typename G>
void writeBoostGeometryWkt(const std::string& s, const std::string& p,
const G& g);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktWay);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktPrecision1);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktPrecision2);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktWaySimplify1);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktWaySimplify2);
FRIEND_TEST(OSM_FactHandler, writeBoostGeometryWktWaySimplify3);

void writeBox(const std::string& s, const std::string& p,
const osm2rdf::geometry::Box& box);
FRIEND_TEST(OSM_FactHandler, writeBoxPrecision1);
FRIEND_TEST(OSM_FactHandler, writeBoxPrecision2);
template <typename G>
void writeBoostGeometryGeoJson(const std::string& s, const std::string& p,
const G& geom);
void writeBoostGeometryGeoJson(const std::string& s, const std::string& p,
const osm2rdf::geometry::Relation & geom);
template <typename G>
std::string convertBoostGeometryToGeoJson(const G& geom);
template <typename G>
std::string convertBoostGeometryToWKT(const G& geom);

void writeTag(const std::string& s, const osm2rdf::osm::Tag& tag);
FRIEND_TEST(OSM_FactHandler, writeTag_AdminLevel);
Expand Down
4 changes: 3 additions & 1 deletion include/osm2rdf/ttl/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ const static inline std::string NAMESPACE__WIKIDATA_ENTITY = "wd";
const static inline std::string NAMESPACE__XML_SCHEMA = "xsd";

// Generated constants (depending on output format)
inline std::string IRI__GEOSPARQL__HAS_SERIALIZATION;
inline std::string IRI__GEOSPARQL__AS_GEOJSON;
inline std::string IRI__GEOSPARQL__AS_WKT;
inline std::string IRI__GEOSPARQL__GEOJSON_LITERAL;
inline std::string IRI__GEOSPARQL__HAS_GEOMETRY;
inline std::string IRI__GEOSPARQL__HAS_SERIALIZATION;
inline std::string IRI__GEOSPARQL__WKT_LITERAL;

inline std::string IRI__OSM2RDF_CONTAINS_NON_AREA;
Expand Down
40 changes: 21 additions & 19 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ std::string osm2rdf::config::Config::getInfo(std::string_view prefix) const {
<< osm2rdf::config::constants::ADD_WAY_NODE_SPATIAL_METADATA_INFO;
}
}
if (simplifyWKT > 0) {
oss << "\n" << prefix << osm2rdf::config::constants::SIMPLIFY_WKT_INFO;
if (geometriesDumpMinNumPointsForSimplification > 0) {
oss << "\n" << prefix << osm2rdf::config::constants::SIMPLIFY_GEOMETRIES_DUMP_INFO;
oss << "\n"
<< prefix << osm2rdf::config::constants::SIMPLIFY_WKT_DEVIATION_INFO
<< std::to_string(wktDeviation);
<< prefix << osm2rdf::config::constants::GEOMETRIES_DUMP_DEVIATION_INFO
<< std::to_string(geometriesDumpDeviation);
}
if (skipWikiLinks) {
oss << "\n" << prefix << osm2rdf::config::constants::SKIP_WIKI_LINKS_INFO;
}
oss << "\n"
<< prefix << osm2rdf::config::constants::WKT_PRECISION_INFO
<< std::to_string(wktPrecision);
<< prefix << osm2rdf::config::constants::GEOMETRIES_DUMP_PRECISION_INFO
<< std::to_string(geometriesDumpPrecision);
if (!semicolonTagKeys.empty()) {
oss << "\n"
<< prefix << osm2rdf::config::constants::SEMICOLON_TAG_KEYS_INFO;
Expand Down Expand Up @@ -425,20 +425,22 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
osm2rdf::config::constants::APPROX_SPATIAL_REL_OPTION_HELP);
auto simplifyWKTOp =
parser.add<popl::Value<uint16_t>, popl::Attribute::advanced>(
osm2rdf::config::constants::SIMPLIFY_WKT_OPTION_SHORT,
osm2rdf::config::constants::SIMPLIFY_WKT_OPTION_LONG,
osm2rdf::config::constants::SIMPLIFY_WKT_OPTION_HELP, simplifyWKT);
osm2rdf::config::constants::SIMPLIFY_GEOMETRIES_DUMP_OPTION_SHORT,
osm2rdf::config::constants::SIMPLIFY_GEOMETRIES_DUMP_OPTION_LONG,
osm2rdf::config::constants::SIMPLIFY_GEOMETRIES_DUMP_OPTION_HELP,
geometriesDumpMinNumPointsForSimplification);
auto wktDeviationOp =
parser.add<popl::Value<double>, popl::Attribute::expert>(
osm2rdf::config::constants::SIMPLIFY_WKT_DEVIATION_OPTION_SHORT,
osm2rdf::config::constants::SIMPLIFY_WKT_DEVIATION_OPTION_LONG,
osm2rdf::config::constants::SIMPLIFY_WKT_DEVIATION_OPTION_HELP,
wktDeviation);
osm2rdf::config::constants::GEOMETRIES_DUMP_DEVIATION_OPTION_SHORT,
osm2rdf::config::constants::GEOMETRIES_DUMP_DEVIATION_OPTION_LONG,
osm2rdf::config::constants::GEOMETRIES_DUMP_DEVIATION_OPTION_HELP,
geometriesDumpDeviation);
auto wktPrecisionOp =
parser.add<popl::Value<uint16_t>, popl::Attribute::advanced>(
osm2rdf::config::constants::WKT_PRECISION_OPTION_SHORT,
osm2rdf::config::constants::WKT_PRECISION_OPTION_LONG,
osm2rdf::config::constants::WKT_PRECISION_OPTION_HELP, wktPrecision);
osm2rdf::config::constants::GEOMETRIES_DUMP_PRECISION_OPTION_SHORT,
osm2rdf::config::constants::GEOMETRIES_DUMP_PRECISION_OPTION_LONG,
osm2rdf::config::constants::GEOMETRIES_DUMP_PRECISION_OPTION_HELP,
geometriesDumpPrecision);

auto writeDotFilesOp = parser.add<popl::Switch, popl::Attribute::expert>(
osm2rdf::config::constants::WRITE_DAG_DOT_FILES_OPTION_SHORT,
Expand Down Expand Up @@ -552,9 +554,9 @@ void osm2rdf::config::Config::fromArgs(int argc, char** argv) {
simplifyGeometriesInnerOuter = simplifyGeometriesInnerOuterOp->value();
dontUseInnerOuterGeoms = dontUseInnerOuterGeomsOp->value();
approximateSpatialRels = approximateSpatialRelsOp->value();
simplifyWKT = simplifyWKTOp->value();
wktDeviation = wktDeviationOp->value();
wktPrecision = wktPrecisionOp->value();
geometriesDumpMinNumPointsForSimplification = simplifyWKTOp->value();
geometriesDumpDeviation = wktDeviationOp->value();
geometriesDumpPrecision = wktPrecisionOp->value();

addWayNodeOrder |= addWayNodeGeometry;
addWayNodeOrder |= addWayNodeSpatialMetadata;
Expand Down
Loading