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.
This commit is contained in:
Sarah Hoffmann
2025-06-05 23:06:21 +02:00
parent 771baaa45b
commit 1ee13a96c7
5 changed files with 30 additions and 31 deletions

View File

@ -31,9 +31,7 @@ osmdata_t::osmdata_t(std::shared_ptr<middle_t> mid,
: m_mid(std::move(mid)), m_output(std::move(output)),
m_connection_params(options.connection_params), m_bbox(options.bbox),
m_num_procs(options.num_procs), m_append(options.append),
m_droptemp(options.droptemp),
m_with_extra_attrs(options.extra_attributes ||
options.output_backend == "flex")
m_droptemp(options.droptemp)
{
assert(m_mid);
assert(m_output);
@ -60,13 +58,8 @@ void osmdata_t::node(osmium::Node const &node)
return;
}
bool const has_tags_or_attrs = m_with_extra_attrs || !node.tags().empty();
if (m_append) {
if (has_tags_or_attrs) {
m_output->node_modify(node);
} else {
m_output->node_delete(node.id());
}
m_output->node_modify(node);
// Version 1 means this is a new node, so there can't be an existing
// 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)
if (node.version() != 1) {
m_changed_nodes.push_back(node.id());
}
} else if (has_tags_or_attrs) {
} else {
m_output->node_add(node);
}
}
@ -105,13 +98,8 @@ void osmdata_t::way(osmium::Way &way)
return;
}
bool const has_tags_or_attrs = m_with_extra_attrs || !way.tags().empty();
if (m_append) {
if (has_tags_or_attrs) {
m_output->way_modify(&way);
} else {
m_output->way_delete(way.id());
}
m_output->way_modify(&way);
// Version 1 means this is a new way, so there can't be an existing
// 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)
if (way.version() != 1) {
m_changed_ways.push_back(way.id());
}
} else if (has_tags_or_attrs) {
} else {
m_output->way_add(&way);
}
}
@ -177,15 +165,10 @@ void osmdata_t::relation(osmium::Relation const &rel)
return;
}
bool const has_tags_or_attrs = m_with_extra_attrs || !rel.tags().empty();
if (m_append) {
if (has_tags_or_attrs) {
m_output->relation_modify(rel);
} else {
m_output->relation_delete(rel.id());
}
m_output->relation_modify(rel);
m_changed_relations.push_back(rel.id());
} else if (has_tags_or_attrs) {
} else {
m_output->relation_add(rel);
}
}

View File

@ -117,7 +117,6 @@ private:
unsigned int m_num_procs;
bool m_append;
bool m_droptemp;
bool m_with_extra_attrs;
};
#endif // OSM2PGSQL_OSMDATA_HPP

View File

@ -206,6 +206,10 @@ void output_pgsql_t::wait()
void output_pgsql_t::node_add(osmium::Node const &node)
{
if (m_ignore_untagged_objects && node.tags().empty()) {
return;
}
taglist_t outtags;
if (m_tagtransform->filter_tags(node, nullptr, nullptr, &outtags)) {
return;
@ -219,6 +223,10 @@ void output_pgsql_t::node_add(osmium::Node const &node)
void output_pgsql_t::way_add(osmium::Way *way)
{
if (m_ignore_untagged_objects && way->tags().empty()) {
return;
}
bool polygon = false;
bool roads = false;
taglist_t outtags;
@ -317,6 +325,10 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
void output_pgsql_t::relation_add(osmium::Relation const &rel)
{
if (m_ignore_untagged_objects && rel.tags().empty()) {
return;
}
char const *const type = rel.tags()["type"];
/* 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,
m_enable_way_area = read_style_file(options.style, &exlist);
m_ignore_untagged_objects = !options.extra_attributes;
m_tagtransform = tagtransform_t::make_tagtransform(&options, exlist);
auto copy_thread =
@ -507,6 +521,7 @@ output_pgsql_t::output_pgsql_t(
std::shared_ptr<db_copy_thread_t> const &copy_thread)
: output_t(other, mid), m_tagtransform(other->m_tagtransform->clone()),
m_enable_way_area(other->m_enable_way_area),
m_ignore_untagged_objects(other->m_ignore_untagged_objects),
m_proj(get_options()->projection), m_expire_config(other->m_expire_config),
m_expire(get_options()->expire_tiles_zoom, get_options()->projection),
m_buffer(1024, osmium::memory::Buffer::auto_grow::yes),

View File

@ -100,6 +100,8 @@ private:
//enable output of a generated way_area tag to either hstore or its own column
bool m_enable_way_area;
// handle objects without tags as if they were not there
bool m_ignore_untagged_objects;
std::array<std::unique_ptr<table_t>, t_MAX> m_tables;

View File

@ -154,13 +154,13 @@ TEST_CASE("parse xml file")
testing::parse_file(options, middle, output, "test_multipolygon.osm",
false);
REQUIRE(output->sum_ids == 4728);
REQUIRE(output->sum_nds == 186);
REQUIRE(output->sum_ids == 73514);
REQUIRE(output->sum_nds == 495);
REQUIRE(output->sum_members == 146);
REQUIRE(output->node.added == 0);
REQUIRE(output->node.added == 353);
REQUIRE(output->node.modified == 0);
REQUIRE(output->node.deleted == 0);
REQUIRE(output->way.added == 48);
REQUIRE(output->way.added == 140);
REQUIRE(output->way.modified == 0);
REQUIRE(output->way.deleted == 0);
REQUIRE(output->relation.added == 40);
@ -188,8 +188,8 @@ TEST_CASE("parse diff file")
testing::parse_file(options, middle, output, "008-ch.osc.gz", false);
REQUIRE(output->node.added == 0);
REQUIRE(output->node.modified == 153);
REQUIRE(output->node.deleted == 17796);
REQUIRE(output->node.modified == 1176);
REQUIRE(output->node.deleted == 16773);
REQUIRE(output->way.added == 0);
REQUIRE(output->way.modified == 161);
REQUIRE(output->way.deleted == 4);