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

Report missing nodes in the input #2159

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
33 changes: 31 additions & 2 deletions src/output-flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>::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;
Expand Down Expand Up @@ -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<osmium::Way>()) {
middle.nodes_get_list(&(way.nodes()));
get_nodes(middle, &way);
}
}

Expand Down
39 changes: 39 additions & 0 deletions tests/bdd/flex/missing-nodes.feature
Original file line number Diff line number Diff line change
@@ -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
"""