|
| 1 | +#include "check-order.hpp" |
| 2 | +#include "format.hpp" |
| 3 | + |
| 4 | +#include <osmium/osm/relation.hpp> |
| 5 | +#include <osmium/osm/types.hpp> |
| 6 | +#include <osmium/osm/way.hpp> |
| 7 | + |
| 8 | +void check_order_t::warning(char const *msg, osmid_t id) |
| 9 | +{ |
| 10 | + fmt::print(stderr, |
| 11 | + "\nWARNING: {}: {}\n" |
| 12 | + " Unordered input files do not work correctly in all\n" |
| 13 | + " cases. Future versions of osm2pgsql will require\n" |
| 14 | + " ordered files. Use the 'sort' command of osmium tool\n" |
| 15 | + " to sort them first.\n\n", |
| 16 | + msg, id); |
| 17 | + m_issued_warning = true; |
| 18 | +} |
| 19 | + |
| 20 | +void check_order_t::node(const osmium::Node &node) |
| 21 | +{ |
| 22 | + if (m_issued_warning) { |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + if (m_max_way_id > std::numeric_limits<osmid_t>::min()) { |
| 27 | + warning("Found a node after a way", node.id()); |
| 28 | + } |
| 29 | + if (m_max_relation_id > std::numeric_limits<osmid_t>::min()) { |
| 30 | + warning("Found a node after a relation", node.id()); |
| 31 | + } |
| 32 | + |
| 33 | + if (m_max_node_id == node.id()) { |
| 34 | + warning("Node ID twice in input. Maybe you are using a history or " |
| 35 | + "non-simplified change file?", |
| 36 | + node.id()); |
| 37 | + } |
| 38 | + if (node.id() < m_max_node_id) { |
| 39 | + warning("Node IDs out of order", node.id()); |
| 40 | + } |
| 41 | + m_max_node_id = node.id(); |
| 42 | +} |
| 43 | + |
| 44 | +void check_order_t::way(const osmium::Way &way) |
| 45 | +{ |
| 46 | + if (m_issued_warning) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + if (m_max_relation_id > std::numeric_limits<osmid_t>::min()) { |
| 51 | + warning("Found a way after a relation", way.id()); |
| 52 | + } |
| 53 | + |
| 54 | + if (m_max_way_id == way.id()) { |
| 55 | + warning("Way ID twice in input. Maybe you are using a history or " |
| 56 | + "non-simplified change file?", |
| 57 | + way.id()); |
| 58 | + } |
| 59 | + if (way.id() < m_max_way_id) { |
| 60 | + warning("Way IDs out of order", way.id()); |
| 61 | + } |
| 62 | + m_max_way_id = way.id(); |
| 63 | +} |
| 64 | + |
| 65 | +void check_order_t::relation(const osmium::Relation &relation) |
| 66 | +{ |
| 67 | + if (m_issued_warning) { |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + if (m_max_relation_id == relation.id()) { |
| 72 | + warning("Relation ID twice in input. Maybe you are using a history or " |
| 73 | + "non-simplified change file?", |
| 74 | + relation.id()); |
| 75 | + } |
| 76 | + if (relation.id() < m_max_relation_id) { |
| 77 | + warning("Relation IDs out of order", relation.id()); |
| 78 | + } |
| 79 | + m_max_relation_id = relation.id(); |
| 80 | +} |
0 commit comments