Skip to content

Commit 479a49d

Browse files
authored
Merge pull request #1251 from joto/warning-negative-ids
Check for negative object ids in input files and output a warning
2 parents fd61965 + fab681f commit 479a49d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/input-handler.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,24 @@ input_handler_t::input_handler_t(osmium::Box const &bbox, bool append,
99
: m_data(osmdata), m_bbox(bbox), m_append(append)
1010
{}
1111

12+
void input_handler_t::negative_id_warning()
13+
{
14+
fmt::print(
15+
stderr,
16+
"\nWARNING: The input file contains at least one object with a\n"
17+
" negative id. Negative ids are not properly supported\n"
18+
" in osm2pgsql (and never were). They will not work in\n"
19+
" future versions at all. You can use the osmium tool to\n"
20+
" 'renumber' your file.\n\n");
21+
m_issued_warning_negative_id = true;
22+
}
23+
1224
void input_handler_t::node(osmium::Node const &node)
1325
{
26+
if (node.id() < 0 && !m_issued_warning_negative_id) {
27+
negative_id_warning();
28+
}
29+
1430
if (m_type != osmium::item_type::node) {
1531
m_type = osmium::item_type::node;
1632
m_data->flush();
@@ -50,6 +66,10 @@ void input_handler_t::node(osmium::Node const &node)
5066

5167
void input_handler_t::way(osmium::Way &way)
5268
{
69+
if (way.id() < 0 && !m_issued_warning_negative_id) {
70+
negative_id_warning();
71+
}
72+
5373
if (m_type != osmium::item_type::way) {
5474
m_type = osmium::item_type::way;
5575
m_data->flush();
@@ -73,6 +93,10 @@ void input_handler_t::way(osmium::Way &way)
7393

7494
void input_handler_t::relation(osmium::Relation const &rel)
7595
{
96+
if (rel.id() < 0 && !m_issued_warning_negative_id) {
97+
negative_id_warning();
98+
}
99+
76100
if (m_type != osmium::item_type::relation) {
77101
m_type = osmium::item_type::relation;
78102
m_data->flush();

src/input-handler.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class input_handler_t : public osmium::handler::Handler
3636
progress_display_t const &progress() const noexcept { return m_progress; }
3737

3838
private:
39+
void negative_id_warning();
40+
3941
osmdata_t const *m_data;
4042

4143
// Bounding box for node import (or invalid Box if everything should be
@@ -50,6 +52,9 @@ class input_handler_t : public osmium::handler::Handler
5052

5153
// Are we running in append mode?
5254
bool m_append;
55+
56+
// Has a warning about a negative id already been issued?
57+
bool m_issued_warning_negative_id = false;
5358
};
5459

5560
#endif // OSM2PGSQL_INPUT_HANDLER_HPP

0 commit comments

Comments
 (0)