forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput-handler.cpp
More file actions
122 lines (108 loc) · 3.54 KB
/
Copy pathinput-handler.cpp
File metadata and controls
122 lines (108 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <osmium/osm.hpp>
#include "format.hpp"
#include "input-handler.hpp"
#include "osmdata.hpp"
input_handler_t::input_handler_t(osmium::Box const &bbox, bool append,
osmdata_t const *osmdata)
: m_data(osmdata), m_bbox(bbox), m_append(append)
{}
void input_handler_t::negative_id_warning()
{
fmt::print(
stderr,
"\nWARNING: The input file contains at least one object with a\n"
" negative id. Negative ids are not properly supported\n"
" in osm2pgsql (and never were). They will not work in\n"
" future versions at all. You can use the osmium tool to\n"
" 'renumber' your file.\n\n");
m_issued_warning_negative_id = true;
}
void input_handler_t::node(osmium::Node const &node)
{
if (node.id() < 0 && !m_issued_warning_negative_id) {
negative_id_warning();
}
if (m_type != osmium::item_type::node) {
m_type = osmium::item_type::node;
m_data->flush();
}
if (node.deleted()) {
if (!m_append) {
throw std::runtime_error{"Input file contains deleted objects but "
"you are not in append mode."};
}
m_data->node_delete(node.id());
} else {
// if the node is not valid, then node.location.lat/lon() can throw.
// we probably ought to treat invalid locations as if they were
// deleted and ignore them.
if (!node.location().valid()) {
fmt::print(
stderr,
"WARNING: Node {} (version {}) has an invalid location and has "
"been ignored. This is not expected to happen with recent "
"planet files, so please check that your input is correct.\n",
node.id(), node.version());
return;
}
if (!m_bbox.valid() || m_bbox.contains(node.location())) {
if (m_append) {
m_data->node_modify(node);
} else {
m_data->node_add(node);
}
m_progress.add_node(node.id());
}
}
}
void input_handler_t::way(osmium::Way &way)
{
if (way.id() < 0 && !m_issued_warning_negative_id) {
negative_id_warning();
}
if (m_type != osmium::item_type::way) {
m_type = osmium::item_type::way;
m_data->flush();
}
if (way.deleted()) {
if (!m_append) {
throw std::runtime_error{"Input file contains deleted objects but "
"you are not in append mode."};
}
m_data->way_delete(way.id());
} else {
if (m_append) {
m_data->way_modify(&way);
} else {
m_data->way_add(&way);
}
}
m_progress.add_way(way.id());
}
void input_handler_t::relation(osmium::Relation const &rel)
{
if (rel.id() < 0 && !m_issued_warning_negative_id) {
negative_id_warning();
}
if (m_type != osmium::item_type::relation) {
m_type = osmium::item_type::relation;
m_data->flush();
}
if (rel.deleted()) {
if (!m_append) {
throw std::runtime_error{"Input file contains deleted objects but "
"you are not in append mode."};
}
m_data->relation_delete(rel.id());
} else {
if (rel.members().size() > 32767) {
return;
}
if (m_append) {
m_data->relation_modify(rel);
} else {
m_data->relation_add(rel);
}
}
m_progress.add_rel(rel.id());
}