Skip to content

Commit 73c622b

Browse files
authored
Merge pull request #2159 from joto/detect-missing-nodes
Report missing nodes in the input
2 parents 2cd71a6 + 6214c39 commit 73c622b

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

src/output-flex.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,39 @@ void output_flex_t::way_cache_t::init(osmium::Way *way)
499499
m_way = way;
500500
}
501501

502+
static std::size_t get_nodes(middle_query_t const &middle, osmium::Way *way)
503+
{
504+
constexpr std::size_t const max_missing_nodes = 100;
505+
static std::size_t count_missing_nodes = 0;
506+
507+
auto const count = middle.nodes_get_list(&way->nodes());
508+
509+
if (count_missing_nodes <= max_missing_nodes &&
510+
count != way->nodes().size()) {
511+
util::string_joiner_t id_list{','};
512+
for (auto const &nr : way->nodes()) {
513+
if (!nr.location().valid()) {
514+
id_list.add(fmt::to_string(nr.ref()));
515+
++count_missing_nodes;
516+
}
517+
}
518+
519+
log_debug("Missing nodes in way {}: {}", way->id(), id_list());
520+
521+
if (count_missing_nodes > max_missing_nodes) {
522+
log_debug("Reported more than {} missing nodes, no further missing "
523+
"nodes will be reported!",
524+
max_missing_nodes);
525+
}
526+
}
527+
528+
return count;
529+
}
530+
502531
std::size_t output_flex_t::way_cache_t::add_nodes(middle_query_t const &middle)
503532
{
504533
if (m_num_way_nodes == std::numeric_limits<std::size_t>::max()) {
505-
m_num_way_nodes = middle.nodes_get_list(&m_way->nodes());
534+
m_num_way_nodes = get_nodes(middle, m_way);
506535
}
507536

508537
return m_num_way_nodes;
@@ -547,7 +576,7 @@ bool output_flex_t::relation_cache_t::add_members(middle_query_t const &middle)
547576
}
548577

549578
for (auto &way : m_members_buffer.select<osmium::Way>()) {
550-
middle.nodes_get_list(&(way.nodes()));
579+
get_nodes(middle, &way);
551580
}
552581
}
553582

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Feature: Test handling of missing nodes
2+
3+
Background:
4+
Given the lua style
5+
"""
6+
local tables = {}
7+
8+
tables.line = osm2pgsql.define_table{
9+
name = 'osm2pgsql_test_lines',
10+
ids = { type = 'way', id_column = 'osm_id' },
11+
columns = {
12+
{ column = 'geom', type = 'linestring', projection = 4326 },
13+
}
14+
}
15+
16+
function osm2pgsql.process_way(object)
17+
tables.line:insert({
18+
geom = object:as_linestring()
19+
})
20+
end
21+
"""
22+
23+
Scenario: Missing node is reported
24+
Given the OSM data
25+
"""
26+
n10 v1 dV x10.0 y10.0
27+
n11 v1 dV x10.0 y11.0
28+
w20 v1 dV Thighway=primary Nn10,n11,n12,n13
29+
"""
30+
When running osm2pgsql flex with parameters
31+
| --log-level=debug |
32+
33+
Then table osm2pgsql_test_lines has 1 rows
34+
35+
And the error output contains
36+
"""
37+
Missing nodes in way 20: 12,13
38+
"""
39+

0 commit comments

Comments
 (0)