Skip to content

Commit 90e17f0

Browse files
authored
Merge pull request #934 from lonvia/gazeteer-unnamed-downgrade
gazetteer: handle updates of unnamed places
2 parents 2c598b3 + a257fa7 commit 90e17f0

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

gazetteer-style.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ void gazetteer_style_t::clear()
5151
bool gazetteer_style_t::has_place(std::string const &cls) const
5252
{
5353
return std::any_of(m_main.begin(), m_main.end(), [&](pmaintag_t const &e) {
54-
return strcmp(std::get<0>(e), cls.c_str()) == 0;
54+
if (strcmp(std::get<0>(e), cls.c_str()) == 0) {
55+
if (std::get<2>(e) & SF_MAIN_NAMED)
56+
return !m_names.empty();
57+
// XXX should handle SF_MAIN_NAMED_KEY as well
58+
59+
return true;
60+
}
61+
62+
return false;
5563
});
5664
}
5765

@@ -381,7 +389,7 @@ void gazetteer_style_t::process_tags(osmium::OSMObject const &o)
381389
}
382390
}
383391

384-
void gazetteer_style_t::copy_out(osmium::OSMObject const &o,
392+
bool gazetteer_style_t::copy_out(osmium::OSMObject const &o,
385393
std::string const &geom, db_copy_mgr_t &buffer)
386394
{
387395
bool any = false;
@@ -391,14 +399,17 @@ void gazetteer_style_t::copy_out(osmium::OSMObject const &o,
391399
}
392400
}
393401

394-
if (!any) {
395-
for (auto const &main : m_main) {
396-
if ((std::get<2>(main) & SF_MAIN_FALLBACK) &&
397-
copy_out_maintag(main, o, geom, buffer)) {
398-
break;
399-
}
402+
if (any)
403+
return true;
404+
405+
for (auto const &main : m_main) {
406+
if ((std::get<2>(main) & SF_MAIN_FALLBACK) &&
407+
copy_out_maintag(main, o, geom, buffer)) {
408+
return true;
400409
}
401410
}
411+
412+
return false;
402413
}
403414

404415
bool gazetteer_style_t::copy_out_maintag(pmaintag_t const &tag,

gazetteer-style.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class gazetteer_style_t
6161
public:
6262
void load_style(std::string const &filename);
6363
void process_tags(osmium::OSMObject const &o);
64-
void copy_out(osmium::OSMObject const &o, std::string const &geom,
64+
bool copy_out(osmium::OSMObject const &o, std::string const &geom,
6565
db_copy_mgr_t &buffer);
6666
bool has_place(std::string const &cls) const;
6767

output-gazetteer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ int output_gazetteer_t::process_node(osmium::Node const &node)
146146
/* Are we interested in this item? */
147147
if (m_style.has_data()) {
148148
auto wkb = m_builder.get_wkb_node(node.location());
149-
m_style.copy_out(node, wkb, m_copy);
149+
if (!m_style.copy_out(node, wkb, m_copy))
150+
delete_unused_full("N", node.id());
150151
}
151152

152153
return 0;
@@ -178,7 +179,8 @@ int output_gazetteer_t::process_way(osmium::Way *way)
178179
geom = wkbs[0];
179180
}
180181

181-
m_style.copy_out(*way, geom, m_copy);
182+
if (!m_style.copy_out(*way, geom, m_copy))
183+
delete_unused_full("W", way->id());
182184
}
183185

184186
return 0;
@@ -229,7 +231,8 @@ int output_gazetteer_t::process_relation(osmium::Relation const &rel)
229231
: m_builder.get_wkb_multipolygon(rel, osmium_buffer);
230232

231233
if (!geoms.empty()) {
232-
m_style.copy_out(rel, geoms[0], m_copy);
234+
if (!m_style.copy_out(rel, geoms[0], m_copy))
235+
delete_unused_full("R", rel.id());
233236
}
234237

235238
return 0;

0 commit comments

Comments
 (0)