[Tile-serving] [openstreetmap/osm2pgsql] Gazetteer: move main tag filtering into processing function (#1018)

Sarah Hoffmann notifications at github.com
Sat Dec 7 08:38:09 UTC 2019


lonvia commented on this pull request.

The remaining comments refer to code that wasn't actually changed, just foramtted. So I left them.

>  
-    for (auto const &item : tags) {
-        char const *k = item.key();
-        if (prefix.compare(0, plen, k) == 0 &&
-            (k[plen] == '\0' || k[plen] == ':')) {
-            ret.push_back(&item);
+    char const *operator ()(osmium::Tag const &t) const noexcept
+    {
+        if (strncmp(t.key(), m_domain, m_len) == 0

Done.

>          }
+
+        return nullptr;

I've added class documentation. Unit tests are welcome but are currently pretty low on my todo list. ymmv.

> -                if (!postcode) {
-                    postcode = v;
-                }
-            } else if (strcmp(addr_key, "country") == 0) {
-                if (!country && strlen(v) == 2) {
-                    country = v;
-                }
-            } else {
-                bool first = std::none_of(
-                    m_address.begin(), m_address.end(), [&](ptag_t const &t) {
-                        return strcmp(t.first, addr_key) == 0;
-                    });
-                if (first) {
-                    m_address.emplace_back(addr_key, v);
-                }
+            bool first = std::none_of(

Done. I think this was the only one in code that was actually changed.

>              return false;
-        }
+            });
+
+    // any non-fallback mains left?
+    bool has_primary =
+        std::any_of(m_main.begin(), mend, [](pmaintag_t const &t) {
+            return !(std::get<2>(t) & SF_MAIN_FALLBACK);
+            });
+
+    if (has_primary) {
+        // remove all fallbacks
+        mend = std::remove_if(m_main.begin(), mend, [&](pmaintag_t const &t) {

This was intentional because it's the end of the same vector.

> +{
+    for (auto const &tag : m_main) {
+        buffer.new_line();
+        // osm_id
+        buffer.add_column(o.id());
+        // osm_type
+        char const osm_type[2] = {
+            (char)toupper(osmium::item_type_to_char(o.type())), '\0'};
+        buffer.add_column(osm_type);
+        // class
+        buffer.add_column(std::get<0>(tag));
+        // type
+        buffer.add_column(std::get<1>(tag));
+        // names
+        if (std::get<2>(tag) & SF_MAIN_NAMED_KEY) {
+            DomainMatcher m(std::get<0>(tag));

Done,

> @@ -53,6 +53,22 @@ class db_deleter_place_t
     std::vector<item_t> m_deletables;
 };
 
+class gazetteer_copy_mgr_t : public db_copy_mgr_t<db_deleter_place_t>
+{
+public:
+    gazetteer_copy_mgr_t(std::shared_ptr<db_copy_thread_t> const &processor)
+    : db_copy_mgr_t<db_deleter_place_t>(processor),
+      m_table(std::make_shared<db_target_descr_t>("place", "place_id"))
+    {}
+
+    using db_copy_mgr_t<db_deleter_place_t>::new_line;
+
+    void new_line() { new_line(m_table); }

Renamed the function.

> +    CHECK(1 == node_count(conn, 201, "building"));
+    CHECK(0 == node_count(conn, 202, "building"));
+}
+
+TEST_CASE("Main tag deleted")
+{
+    import("n1 Tamenity=restaurant x12.3 y3\n"
+           "n2 Thighway=bus_stop,railway=stop,name=X x56.4 y-4\n");
+
+    auto conn = db.connect();
+
+    CHECK(1 == node_count(conn, 1, "amenity"));
+    CHECK(1 == node_count(conn, 2, "highway"));
+    CHECK(1 == node_count(conn, 2, "railway"));
+
+    update("n1 Tatiy=restaurant x12.3 y3\n"

Done.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/pull/1018#pullrequestreview-328545656
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20191207/42ec9884/attachment.html>


More information about the Tile-serving mailing list