From b03a7dda01844068ca672d2e032afdf01ffca88b Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 3 Feb 2018 10:40:39 +0100 Subject: [PATCH] Skip output for untagged objects When adding objects call output backends only when there are any tags. Only works for the initial import. When updating data, all objects need to be forwarded in case they need to be deleted. That also means that output backends still must be able to handle untagged objects. Fixes #706. --- osmdata.cpp | 23 +++++++++++++++++------ tests/test-parse-xml2.cpp | 8 ++++---- tests/test_output_multi_line_storage.osm | 3 +++ tests/test_output_multi_poly_trivial.osm | 3 +++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/osmdata.cpp b/osmdata.cpp index 48b716e28..9a09c8db1 100644 --- a/osmdata.cpp +++ b/osmdata.cpp @@ -41,9 +41,13 @@ int osmdata_t::node_add(osmium::Node const &node) mid->nodes_set(node); int status = 0; - for (auto &out : outs) { - status |= out->node_add(node); + + if (!node.tags().empty()) { + for (auto &out : outs) { + status |= out->node_add(node); + } } + return status; } @@ -52,9 +56,13 @@ int osmdata_t::way_add(osmium::Way *way) mid->ways_set(*way); int status = 0; - for (auto& out: outs) { - status |= out->way_add(way); + + if (!way->tags().empty()) { + for (auto& out: outs) { + status |= out->way_add(way); + } } + return status; } @@ -63,9 +71,12 @@ int osmdata_t::relation_add(osmium::Relation const &rel) mid->relations_set(rel); int status = 0; - for (auto& out: outs) { - status |= out->relation_add(rel); + if (!rel.tags().empty()) { + for (auto& out: outs) { + status |= out->relation_add(rel); + } } + return status; } diff --git a/tests/test-parse-xml2.cpp b/tests/test-parse-xml2.cpp index e9db2ac96..cd0429d73 100644 --- a/tests/test-parse-xml2.cpp +++ b/tests/test-parse-xml2.cpp @@ -93,11 +93,11 @@ int main(int argc, char *argv[]) { parser.stream_file(inputfile, ""); - assert_equal(out_test->sum_ids, 73514L); - assert_equal(out_test->num_nodes, 353L); - assert_equal(out_test->num_ways, 140L); + assert_equal(out_test->sum_ids, 4728L); + assert_equal(out_test->num_nodes, 0L); + assert_equal(out_test->num_ways, 48L); assert_equal(out_test->num_relations, 40L); - assert_equal(out_test->num_nds, 495L); + assert_equal(out_test->num_nds, 186L); assert_equal(out_test->num_members, 146L); return 0; diff --git a/tests/test_output_multi_line_storage.osm b/tests/test_output_multi_line_storage.osm index 425598e5a..5f45ca29a 100644 --- a/tests/test_output_multi_line_storage.osm +++ b/tests/test_output_multi_line_storage.osm @@ -19,15 +19,18 @@ + + + diff --git a/tests/test_output_multi_poly_trivial.osm b/tests/test_output_multi_poly_trivial.osm index 3f82861e6..d6bb50c20 100644 --- a/tests/test_output_multi_poly_trivial.osm +++ b/tests/test_output_multi_poly_trivial.osm @@ -19,6 +19,7 @@ which contains both w1 and w2. + @@ -26,6 +27,7 @@ which contains both w1 and w2. + @@ -33,6 +35,7 @@ which contains both w1 and w2. +