diff --git a/src/output-flex.cpp b/src/output-flex.cpp index 030c0055a..a80fab239 100644 --- a/src/output-flex.cpp +++ b/src/output-flex.cpp @@ -499,10 +499,39 @@ void output_flex_t::way_cache_t::init(osmium::Way *way) m_way = way; } +static std::size_t get_nodes(middle_query_t const &middle, osmium::Way *way) +{ + constexpr std::size_t const max_missing_nodes = 100; + static std::size_t count_missing_nodes = 0; + + auto const count = middle.nodes_get_list(&way->nodes()); + + if (count_missing_nodes <= max_missing_nodes && + count != way->nodes().size()) { + util::string_joiner_t id_list{','}; + for (auto const &nr : way->nodes()) { + if (!nr.location().valid()) { + id_list.add(fmt::to_string(nr.ref())); + ++count_missing_nodes; + } + } + + log_debug("Missing nodes in way {}: {}", way->id(), id_list()); + + if (count_missing_nodes > max_missing_nodes) { + log_debug("Reported more than {} missing nodes, no further missing " + "nodes will be reported!", + max_missing_nodes); + } + } + + return count; +} + std::size_t output_flex_t::way_cache_t::add_nodes(middle_query_t const &middle) { if (m_num_way_nodes == std::numeric_limits::max()) { - m_num_way_nodes = middle.nodes_get_list(&m_way->nodes()); + m_num_way_nodes = get_nodes(middle, m_way); } return m_num_way_nodes; @@ -547,7 +576,7 @@ bool output_flex_t::relation_cache_t::add_members(middle_query_t const &middle) } for (auto &way : m_members_buffer.select()) { - middle.nodes_get_list(&(way.nodes())); + get_nodes(middle, &way); } } diff --git a/tests/bdd/flex/missing-nodes.feature b/tests/bdd/flex/missing-nodes.feature new file mode 100644 index 000000000..f15b0cc92 --- /dev/null +++ b/tests/bdd/flex/missing-nodes.feature @@ -0,0 +1,39 @@ +Feature: Test handling of missing nodes + + Background: + Given the lua style + """ + local tables = {} + + tables.line = osm2pgsql.define_table{ + name = 'osm2pgsql_test_lines', + ids = { type = 'way', id_column = 'osm_id' }, + columns = { + { column = 'geom', type = 'linestring', projection = 4326 }, + } + } + + function osm2pgsql.process_way(object) + tables.line:insert({ + geom = object:as_linestring() + }) + end + """ + + Scenario: Missing node is reported + Given the OSM data + """ + n10 v1 dV x10.0 y10.0 + n11 v1 dV x10.0 y11.0 + w20 v1 dV Thighway=primary Nn10,n11,n12,n13 + """ + When running osm2pgsql flex with parameters + | --log-level=debug | + + Then table osm2pgsql_test_lines has 1 rows + + And the error output contains + """ + Missing nodes in way 20: 12,13 + """ +