Skip to content

Commit 03fe35b

Browse files
committed
Add country if it is needed and is missing in hierarchy
1 parent 4bebc34 commit 03fe35b

File tree

6 files changed

+127
-101
lines changed

6 files changed

+127
-101
lines changed

importer/src/config.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef GEOCODER_CONFIG_H
22
#define GEOCODER_CONFIG_H
33

4+
#include <cstdint>
5+
46
#define TEMPORARY "TEMPORARY" // set to empty if need to debug import
57

68
/// if there are more expansions that specified, this object will be dropped from normalization
@@ -14,7 +16,7 @@
1416

1517
#define GEOCODER_IMPORTER_POSTGRES "GEOCODER_IMPORTER_POSTGRES"
1618

17-
typedef unsigned long hindex;
19+
typedef uint64_t hindex;
1820
typedef long long int sqlid; /// type used by IDs in SQLite
1921

20-
#endif
22+
#endif

importer/src/hierarchy.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ void Hierarchy::cleanup()
7979
void Hierarchy::set_country(const std::string &country, hindex id)
8080
{
8181
if (!m_items.count(id))
82-
std::cout << "Missing country in the database: " << country << "\n";
82+
{
83+
std::cout << "Missing country in the database: " << country << " / " << id << "\n";
84+
for (auto item : root_items())
85+
if (item->country() == country)
86+
item->print_branch(0);
87+
}
88+
8389

8490
auto parent = m_items[id];
8591
for (auto root_iter = m_root.begin(); root_iter != m_root.end(); ++root_iter)
@@ -91,7 +97,7 @@ void Hierarchy::set_country(const std::string &country, hindex id)
9197
parent->add_child(item);
9298
remove.insert(item);
9399
}
94-
std::cout << "Relocated to country: " << remove.size() << "\n";
100+
std::cout << "Relocated to country: " << country << " - " << remove.size() << "\n";
95101
for (auto item : remove)
96102
root_iter->second.erase(item);
97103
}
@@ -150,6 +156,11 @@ std::set<std::string> Hierarchy::get_root_countries() const
150156
return missing;
151157
}
152158

159+
bool Hierarchy::has_item(hindex id) const
160+
{
161+
return m_items.count(id);
162+
}
163+
153164
void Hierarchy::print(bool full) const
154165
{
155166
std::set<hindex> root_ids;

importer/src/hierarchy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Hierarchy
2727

2828
size_t get_missing_count() const { return m_root.size(); }
2929
size_t get_root_count() const;
30+
bool has_item(hindex id) const;
3031

3132
hindex get_next_nonzero_root_parent() const;
3233
std::set<std::string> get_root_countries() const;
@@ -42,4 +43,4 @@ class Hierarchy
4243
std::deque<std::shared_ptr<HierarchyItem> > m_root_finalized;
4344
};
4445

45-
#endif
46+
#endif

importer/src/hierarchyitem.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ HierarchyItem::HierarchyItem(const pqxx::row &row)
2121
m_postcode = row["postcode"].as<std::string>("");
2222
m_latitude = row["latitude"].as<float>(0);
2323
m_longitude = row["longitude"].as<float>(0);
24+
m_osm_id = row["osm_id"].as<uint64_t>(0);
2425

2526
m_data_name = parse_to_map(row["name"].as<std::string>(""));
2627
m_data_extra = parse_to_map(row["extra"].as<std::string>(""));
@@ -272,8 +273,8 @@ void HierarchyItem::print_branch(unsigned int offset) const
272273
std::cout << "house " << m_housenumber << " ";
273274
for (const auto &i : m_data_name)
274275
std::cout << i.first << ": " << i.second << " ";
275-
std::cout << "(" << m_my_index << " " << m_last_child_index - m_my_index << ": " << m_parent_id
276-
<< ", " << m_country << ")\n";
276+
std::cout << "(" << m_my_index << " " << m_last_child_index << ": " << m_last_child_index - m_my_index << ": " << m_parent_id
277+
<< ", " << m_country <<", osmid=" << m_osm_id << ")\n";
277278
if (m_children.size())
278279
std::cout << std::string(offset + 2, ' ') << "|\n";
279280
for (auto c : m_children)

importer/src/hierarchyitem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class HierarchyItem
5252
std::string m_type;
5353
float m_latitude;
5454
float m_longitude;
55+
uint64_t m_osm_id;
5556
std::string m_country;
5657
std::string m_postcode;
5758
std::string m_housenumber;
@@ -67,4 +68,4 @@ class HierarchyItem
6768
static std::set<std::string> s_skip_types;
6869
};
6970

70-
#endif
71+
#endif

0 commit comments

Comments
 (0)