Skip to content

Commit 1ee13a9

Browse files
committed
move special handling of untagged objects into pgsql output
This special handling has been already disabled for flex output when we introduced the untagged callbacks.
1 parent 771baaa commit 1ee13a9

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

src/osmdata.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ osmdata_t::osmdata_t(std::shared_ptr<middle_t> mid,
3131
: m_mid(std::move(mid)), m_output(std::move(output)),
3232
m_connection_params(options.connection_params), m_bbox(options.bbox),
3333
m_num_procs(options.num_procs), m_append(options.append),
34-
m_droptemp(options.droptemp),
35-
m_with_extra_attrs(options.extra_attributes ||
36-
options.output_backend == "flex")
34+
m_droptemp(options.droptemp)
3735
{
3836
assert(m_mid);
3937
assert(m_output);
@@ -60,13 +58,8 @@ void osmdata_t::node(osmium::Node const &node)
6058
return;
6159
}
6260

63-
bool const has_tags_or_attrs = m_with_extra_attrs || !node.tags().empty();
6461
if (m_append) {
65-
if (has_tags_or_attrs) {
66-
m_output->node_modify(node);
67-
} else {
68-
m_output->node_delete(node.id());
69-
}
62+
m_output->node_modify(node);
7063

7164
// Version 1 means this is a new node, so there can't be an existing
7265
// way or relation referencing it, so we don't have to add that node
@@ -75,7 +68,7 @@ void osmdata_t::node(osmium::Node const &node)
7568
if (node.version() != 1) {
7669
m_changed_nodes.push_back(node.id());
7770
}
78-
} else if (has_tags_or_attrs) {
71+
} else {
7972
m_output->node_add(node);
8073
}
8174
}
@@ -105,13 +98,8 @@ void osmdata_t::way(osmium::Way &way)
10598
return;
10699
}
107100

108-
bool const has_tags_or_attrs = m_with_extra_attrs || !way.tags().empty();
109101
if (m_append) {
110-
if (has_tags_or_attrs) {
111-
m_output->way_modify(&way);
112-
} else {
113-
m_output->way_delete(way.id());
114-
}
102+
m_output->way_modify(&way);
115103

116104
// Version 1 means this is a new way, so there can't be an existing
117105
// relation referencing it, so we don't have to add that way to the
@@ -120,7 +108,7 @@ void osmdata_t::way(osmium::Way &way)
120108
if (way.version() != 1) {
121109
m_changed_ways.push_back(way.id());
122110
}
123-
} else if (has_tags_or_attrs) {
111+
} else {
124112
m_output->way_add(&way);
125113
}
126114
}
@@ -177,15 +165,10 @@ void osmdata_t::relation(osmium::Relation const &rel)
177165
return;
178166
}
179167

180-
bool const has_tags_or_attrs = m_with_extra_attrs || !rel.tags().empty();
181168
if (m_append) {
182-
if (has_tags_or_attrs) {
183-
m_output->relation_modify(rel);
184-
} else {
185-
m_output->relation_delete(rel.id());
186-
}
169+
m_output->relation_modify(rel);
187170
m_changed_relations.push_back(rel.id());
188-
} else if (has_tags_or_attrs) {
171+
} else {
189172
m_output->relation_add(rel);
190173
}
191174
}

src/osmdata.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class osmdata_t : public osmium::handler::Handler
117117
unsigned int m_num_procs;
118118
bool m_append;
119119
bool m_droptemp;
120-
bool m_with_extra_attrs;
121120
};
122121

123122
#endif // OSM2PGSQL_OSMDATA_HPP

src/output-pgsql.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ void output_pgsql_t::wait()
206206

207207
void output_pgsql_t::node_add(osmium::Node const &node)
208208
{
209+
if (m_ignore_untagged_objects && node.tags().empty()) {
210+
return;
211+
}
212+
209213
taglist_t outtags;
210214
if (m_tagtransform->filter_tags(node, nullptr, nullptr, &outtags)) {
211215
return;
@@ -219,6 +223,10 @@ void output_pgsql_t::node_add(osmium::Node const &node)
219223

220224
void output_pgsql_t::way_add(osmium::Way *way)
221225
{
226+
if (m_ignore_untagged_objects && way->tags().empty()) {
227+
return;
228+
}
229+
222230
bool polygon = false;
223231
bool roads = false;
224232
taglist_t outtags;
@@ -317,6 +325,10 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
317325

318326
void output_pgsql_t::relation_add(osmium::Relation const &rel)
319327
{
328+
if (m_ignore_untagged_objects && rel.tags().empty()) {
329+
return;
330+
}
331+
320332
char const *const type = rel.tags()["type"];
321333

322334
/* Must have a type field or we ignore it */
@@ -458,6 +470,8 @@ output_pgsql_t::output_pgsql_t(std::shared_ptr<middle_query_t> const &mid,
458470

459471
m_enable_way_area = read_style_file(options.style, &exlist);
460472

473+
m_ignore_untagged_objects = !options.extra_attributes;
474+
461475
m_tagtransform = tagtransform_t::make_tagtransform(&options, exlist);
462476

463477
auto copy_thread =
@@ -507,6 +521,7 @@ output_pgsql_t::output_pgsql_t(
507521
std::shared_ptr<db_copy_thread_t> const &copy_thread)
508522
: output_t(other, mid), m_tagtransform(other->m_tagtransform->clone()),
509523
m_enable_way_area(other->m_enable_way_area),
524+
m_ignore_untagged_objects(other->m_ignore_untagged_objects),
510525
m_proj(get_options()->projection), m_expire_config(other->m_expire_config),
511526
m_expire(get_options()->expire_tiles_zoom, get_options()->projection),
512527
m_buffer(1024, osmium::memory::Buffer::auto_grow::yes),

src/output-pgsql.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class output_pgsql_t : public output_t
100100

101101
//enable output of a generated way_area tag to either hstore or its own column
102102
bool m_enable_way_area;
103+
// handle objects without tags as if they were not there
104+
bool m_ignore_untagged_objects;
103105

104106
std::array<std::unique_ptr<table_t>, t_MAX> m_tables;
105107

tests/test-osm-file-parsing.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ TEST_CASE("parse xml file")
154154
testing::parse_file(options, middle, output, "test_multipolygon.osm",
155155
false);
156156

157-
REQUIRE(output->sum_ids == 4728);
158-
REQUIRE(output->sum_nds == 186);
157+
REQUIRE(output->sum_ids == 73514);
158+
REQUIRE(output->sum_nds == 495);
159159
REQUIRE(output->sum_members == 146);
160-
REQUIRE(output->node.added == 0);
160+
REQUIRE(output->node.added == 353);
161161
REQUIRE(output->node.modified == 0);
162162
REQUIRE(output->node.deleted == 0);
163-
REQUIRE(output->way.added == 48);
163+
REQUIRE(output->way.added == 140);
164164
REQUIRE(output->way.modified == 0);
165165
REQUIRE(output->way.deleted == 0);
166166
REQUIRE(output->relation.added == 40);
@@ -188,8 +188,8 @@ TEST_CASE("parse diff file")
188188
testing::parse_file(options, middle, output, "008-ch.osc.gz", false);
189189

190190
REQUIRE(output->node.added == 0);
191-
REQUIRE(output->node.modified == 153);
192-
REQUIRE(output->node.deleted == 17796);
191+
REQUIRE(output->node.modified == 1176);
192+
REQUIRE(output->node.deleted == 16773);
193193
REQUIRE(output->way.added == 0);
194194
REQUIRE(output->way.modified == 161);
195195
REQUIRE(output->way.deleted == 4);

0 commit comments

Comments
 (0)