static void add_metadata(gdalcpp::Feature& feature, const osmium::OSMObject& object) {
     feature.set_field("version", int32_t(object.version()));
     feature.set_field("changeset", int32_t(object.changeset()));
     feature.set_field("timestamp", object.timestamp().to_iso().c_str());
     feature.set_field("uid", int32_t(object.uid()));
     feature.set_field("user", object.user());
 }
Пример #2
0
 void operator()(const osmium::OSMObject& obj) {
     if (obj.id() != id) {
         if (keep_deleted || obj.visible()) {
             *out = obj;
         }
         id = obj.id();
     }
 }
Пример #3
0
 void add_attributes(const osmium::OSMObject &obj)
 {
     emplace_back("osm_user", obj.user());
     emplace_back("osm_uid", std::to_string(obj.uid()));
     emplace_back("osm_version", std::to_string(obj.version()));
     emplace_back("osm_timestamp", obj.timestamp().to_iso());
     emplace_back("osm_changeset", std::to_string(obj.changeset()));
 }
Пример #4
0
 void output_pubs(const osmium::OSMObject& object) {
     const char* amenity = object.tags()["amenity"];
     if (amenity && !strcmp(amenity, "pub")) {
         const char* name = object.tags()["name"];
         if (name) {
             std::cout << name << std::endl;
         }
     }
 }
Пример #5
0
            void print_meta(const osmium::OSMObject& object) {
                *m_out << m_prefix
                       << "  id="
                       << object.id()
                       << "\n";
                *m_out << m_prefix
                       << "  version="
                       << object.version()
                       << "\n";
                *m_out << m_prefix
                       << "  uid="
                       << object.uid()
                       << "\n";
                *m_out << m_prefix
                       << "  user=|"
                       << object.user()
                       << "|\n";
                *m_out << m_prefix
                       << "  changeset="
                       << object.changeset()
                       << "\n";
                *m_out << m_prefix
                       << "  timestamp="
                       << object.timestamp().to_iso()
                       << "\n";
                *m_out << m_prefix
                       << "  visible="
                       << (object.visible() ? "yes" : "no")
                       << "\n";

                Dump dump(*m_out, m_with_size, m_prefix + "  ");
                osmium::apply(object.cbegin(), object.cend(), dump);
            }
Пример #6
0
void ExportFormatJSON::add_attributes(const osmium::OSMObject& object) {
    if (!options().type.empty()) {
        m_writer.String(options().type);
        if (object.type() == osmium::item_type::area) {
            if (static_cast<const osmium::Area&>(object).from_way()) {
                m_writer.String("way");
            } else {
                m_writer.String("relation");
            }
        } else {
            m_writer.String(osmium::item_type_to_name(object.type()));
        }
    }

    if (!options().id.empty()) {
        m_writer.String(options().id);
        m_writer.Int64(object.type() == osmium::item_type::area ? osmium::area_id_to_object_id(object.id()) : object.id());
    }

    if (!options().version.empty()) {
        m_writer.String(options().version);
        m_writer.Int64(object.version());
    }

    if (!options().changeset.empty()) {
        m_writer.String(options().changeset);
        m_writer.Int64(object.changeset());
    }

    if (!options().uid.empty()) {
        m_writer.String(options().uid);
        m_writer.Int64(object.uid());
    }

    if (!options().user.empty()) {
        m_writer.String(options().user);
        m_writer.String(object.user());
    }

    if (!options().timestamp.empty()) {
        m_writer.String(options().timestamp);
        m_writer.Int64(object.timestamp().seconds_since_epoch());
    }

    if (!options().way_nodes.empty() && object.type() == osmium::item_type::way) {
        m_writer.String(options().way_nodes);
        m_writer.StartArray();
        for (const auto& nr : static_cast<const osmium::Way&>(object).nodes()) {
            m_writer.Int64(nr.ref());
        }
        m_writer.EndArray();
    }
}
Пример #7
0
// escape means we return '\N' for copy mode, otherwise we return just nullptr
void middle_pgsql_t::buffer_store_tags(osmium::OSMObject const &obj, bool attrs,
                                       bool escape)
{
    copy_buffer += "{";

    for (auto const &it : obj.tags()) {
        copy_buffer += "\"";
        buffer_store_string(it.key(), escape);
        copy_buffer += "\",\"";
        buffer_store_string(it.value(), escape);
        copy_buffer += "\",";
    }
    if (attrs) {
        taglist_t extra;
        extra.add_attributes(obj);
        for (auto const &it : extra) {
            copy_buffer += "\"";
            copy_buffer += it.key;
            copy_buffer += "\",\"";
            buffer_store_string(it.value.c_str(), escape);
            copy_buffer += "\",";
        }
    }

    copy_buffer[copy_buffer.size() - 1] = '}';
}
Пример #8
0
                /**
                 * Find this object in the member vectors and add it to all
                 * relations that need it.
                 *
                 * @returns true if the member was added to at least one
                 *          relation and false otherwise
                 */
                bool find_and_add_object(const osmium::OSMObject& object) {
                    auto& mmv = m_collector.member_meta(object.type());
                    auto range = std::equal_range(mmv.begin(), mmv.end(), MemberMeta(object.id()));

                    if (osmium::relations::count_not_removed(range.first, range.second) == 0) {
                        // nothing found
                        return false;
                    }

                    {
                        m_collector.members_buffer().add_item(object);
                        const size_t member_offset = m_collector.members_buffer().commit();

                        for (auto it = range.first; it != range.second; ++it) {
                            it->set_buffer_offset(member_offset);
                        }
                    }

                    for (auto it = range.first; it != range.second; ++it) {
                        MemberMeta& member_meta = *it;
                        if (member_meta.removed()) {
                            break;
                        }
                        assert(member_meta.member_id() == object.id());
                        assert(member_meta.relation_pos() < m_collector.m_relations.size());
                        RelationMeta& relation_meta = m_collector.m_relations[member_meta.relation_pos()];
//                        std::cerr << "  => " << member_meta.member_pos() << " < " << m_collector.get_relation(relation_meta).members().size() << " (id=" << m_collector.get_relation(relation_meta).id() << ")\n";
                        assert(member_meta.member_pos() < m_collector.get_relation(relation_meta).members().size());
//                        std::cerr << "  add way " << member_meta.member_id() << " to rel " << m_collector.get_relation(relation_meta).id() << " at pos " << member_meta.member_pos() << "\n";
                        relation_meta.got_one_member();
                        if (relation_meta.has_all_members()) {
                            const size_t relation_offset = member_meta.relation_pos();
                            m_collector.complete_relation(relation_meta);
                            m_collector.m_relations[relation_offset] = RelationMeta();
                            m_collector.possibly_purge_removed_members();
                        }
                    }

                    // Remove MemberMetas that were marked as removed.
                    mmv.erase(std::remove_if(mmv.begin(), mmv.end(), [](MemberMeta& mm) {
                        return mm.removed();
                    }), mmv.end());

                    return true;
                }
Пример #9
0
            /**
             * Initialize area attributes from the attributes of the given object.
             */
            void initialize_from_object(const osmium::OSMObject& source) {
                osmium::Area& area = object();
                area.set_id(osmium::object_id_to_area_id(source.id(), source.type()));
                area.set_version(source.version());
                area.set_changeset(source.changeset());
                area.set_timestamp(source.timestamp());
                area.set_visible(source.visible());
                area.set_uid(source.uid());

                add_user(source.user());
            }
Пример #10
0
 void update(const osmium::OSMObject& object) {
     update_int64(object.id());
     update_bool(object.visible());
     update_int32(object.version());
     update(object.timestamp());
     update_int32(object.uid());
     update_string(object.user());
     update(object.tags());
 }
 static void add_tags(gdalcpp::Feature& feature, const osmium::OSMObject& object) {
     std::string tags;
     for (const auto& tag : object.tags()) {
         tags += tag.key();
         tags += "=";
         tags += tag.value();
         tags += ",";
     }
     if (!tags.empty()) {
         tags.pop_back();
     }
     feature.set_field("tags", tags.c_str());
 }
Пример #12
0
 void copy_attributes(T& builder, const osmium::OSMObject& object) {
     // The setter functions on the builder object all return the same
     // builder object so they can be chained.
     builder.set_id(object.id())
         .set_version(object.version())
         .set_changeset(object.changeset())
         .set_timestamp(object.timestamp())
         .set_uid(object.uid())
         .set_user(object.user());
 }
Пример #13
0
 void write_meta(const osmium::OSMObject& object) {
     output_int(object.id());
     if (m_options.add_metadata) {
         *m_out += ' ';
         write_field_int('v', object.version());
         *m_out += " d";
         *m_out += (object.visible() ? 'V' : 'D');
         *m_out += ' ';
         write_field_int('c', object.changeset());
         *m_out += ' ';
         write_field_timestamp('t', object.timestamp());
         *m_out += ' ';
         write_field_int('i', object.uid());
         *m_out += " u";
         append_encoded_string(object.user());
     }
     write_tags(object.tags());
 }
Пример #14
0
 void write_meta(const osmium::OSMObject& object) {
     output_formatted("%" PRId64 " v%d d", object.id(), object.version());
     *m_out += (object.visible() ? 'V' : 'D');
     output_formatted(" c%d t", object.changeset());
     *m_out += object.timestamp().to_iso();
     output_formatted(" i%d u", object.uid());
     append_encoded_string(object.user());
     *m_out += " T";
     bool first = true;
     for (const auto& tag : object.tags()) {
         if (first) {
             first = false;
         } else {
             *m_out += ',';
         }
         append_encoded_string(tag.key());
         *m_out += '=';
         append_encoded_string(tag.value());
     }
 }
Пример #15
0
                void write_meta(const osmium::OSMObject& object) {
                    oprintf(m_out, " id=\"%" PRId64 "\"", object.id());

                    if (object.version()) {
                        oprintf(m_out, " version=\"%d\"", object.version());
                    }

                    if (object.timestamp()) {
                        m_out += " timestamp=\"";
                        m_out += object.timestamp().to_iso();
                        m_out += "\"";
                    }

                    if (!object.user_is_anonymous()) {
                        oprintf(m_out, " uid=\"%d\" user=\"", object.uid());
                        xml_string(m_out, object.user());
                        m_out += "\"";
                    }

                    if (object.changeset()) {
                        oprintf(m_out, " changeset=\"%d\"", object.changeset());
                    }

                    if (m_write_visible_flag) {
                        if (object.visible()) {
                            m_out += " visible=\"true\"";
                        } else {
                            m_out += " visible=\"false\"";
                        }
                    }
                }
Пример #16
0
 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
     return const_tie(lhs.type(), lhs.id() < 0, lhs.positive_id(), rhs.version(), rhs.timestamp()) <
            const_tie(rhs.type(), rhs.id() < 0, rhs.positive_id(), lhs.version(), lhs.timestamp());
 }
Пример #17
0
 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
     return lhs.type() == rhs.type() &&
            lhs.id() == rhs.id();
 }
Пример #18
0
 osmium::object_version_type version() const noexcept {
     return m_curr->version();
 }
Пример #19
0
 osmium::object_id_type id() const noexcept {
     return m_curr->id();
 }
Пример #20
0
 /**
  * Current object version is visible at the given timestamp.
  */
 bool is_visible_at(const osmium::Timestamp& timestamp) const noexcept {
     return start_time() <= timestamp && end_time() > timestamp && m_curr->visible();
 }
Пример #21
0
 /**
  * Return the timestamp when the current version of the object is
  * not valid any more, ie the time when the next version of the object
  * is valid. If this is the last version of the object, this will
  * return a special "end of time" timestamp that is guaranteed to
  * be larger than any normal timestamp.
  */
 const osmium::Timestamp end_time() const noexcept {
     return last() ? osmium::end_of_time() : m_next->timestamp();
 }
Пример #22
0
 const osmium::Timestamp start_time() const noexcept {
     return m_curr->timestamp();
 }
Пример #23
0
bool gazetteer_style_t::copy_out_maintag(pmaintag_t const &tag,
                                         osmium::OSMObject const &o,
                                         std::string const &geom,
                                         db_copy_mgr_t &buffer)
{
    std::vector<osmium::Tag const *> domain_name;
    if (std::get<2>(tag) & SF_MAIN_NAMED_KEY) {
        domain_name = domain_names(std::get<0>(tag), o.tags());
        if (domain_name.empty())
            return false;
    }

    if (std::get<2>(tag) & SF_MAIN_NAMED) {
        if (domain_name.empty() && !m_is_named) {
            return false;
        }
    }

    buffer.new_line(place_table);
    // 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 (!domain_name.empty()) {
        auto prefix_len = strlen(std::get<0>(tag)) + 1; // class name and ':'
        buffer.new_hash();
        for (auto *t : domain_name) {
            buffer.add_hash_elem(t->key() + prefix_len, t->value());
        }
        buffer.finish_hash();
    } else {
        bool first = true;
        // operator will be ignored on anything but these classes
        if (m_operator && (std::get<2>(tag) & SF_MAIN_OPERATOR)) {
            buffer.new_hash();
            buffer.add_hash_elem("operator", m_operator);
            first = false;
        }
        for (auto const &entry : m_names) {
            if (first) {
                buffer.new_hash();
                first = false;
            }

            buffer.add_hash_elem(entry.first, entry.second);
        }

        if (first) {
            buffer.add_null_column();
        } else {
            buffer.finish_hash();
        }
    }
    // admin_level
    buffer.add_column(m_admin_level);
    // address
    if (m_address.empty()) {
        buffer.add_null_column();
    } else {
        buffer.new_hash();
        for (auto const &a : m_address) {
            if (strcmp(a.first, "tiger:county") == 0) {
                std::string term;
                auto *end = strchr(a.second, ',');
                if (end) {
                    auto len = (std::string::size_type)(end - a.second);
                    term = std::string(a.second, len);
                } else {
                    term = a.second;
                }
                term += " county";
                buffer.add_hash_elem(a.first, term);
            } else {
                buffer.add_hash_elem(a.first, a.second);
            }
        }
        buffer.finish_hash();
    }
    // extra tags
    if (m_extra.empty()) {
        buffer.add_null_column();
    } else {
        buffer.new_hash();
        for (auto const &entry : m_extra) {
            buffer.add_hash_elem(entry.first, entry.second);
        }
        buffer.finish_hash();
    }
    // add the geometry - encoding it to hex along the way
    buffer.add_hex_geom(geom);

    buffer.finish_line();

    return true;
}
Пример #24
0
bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
                                     int *roads, export_list const &,
                                     taglist_t &out_tags, bool)
{
    switch (o.type()) {
    case osmium::item_type::node:
        lua_getglobal(L, m_node_func.c_str());
        break;
    case osmium::item_type::way:
        lua_getglobal(L, m_way_func.c_str());
        break;
    case osmium::item_type::relation:
        lua_getglobal(L, m_rel_func.c_str());
        break;
    default:
        throw std::runtime_error("Unknown OSM type");
    }

    lua_newtable(L); /* key value table */

    lua_Integer sz = 0;
    for (auto const &t : o.tags()) {
        lua_pushstring(L, t.key());
        lua_pushstring(L, t.value());
        lua_rawset(L, -3);
        ++sz;
    }
    if (m_extra_attributes && o.version() > 0) {
        taglist_t tags;
        tags.add_attributes(o);
        for (auto const &t : tags) {
            lua_pushstring(L, t.key.c_str());
            lua_pushstring(L, t.value.c_str());
            lua_rawset(L, -3);
        }
        sz += tags.size();
    }

    lua_pushinteger(L, sz);

    if (lua_pcall(L, 2, (o.type() == osmium::item_type::way) ? 4 : 2, 0)) {
        fprintf(stderr,
                "Failed to execute lua function for basic tag processing: %s\n",
                lua_tostring(L, -1));
        /* lua function failed */
        return 1;
    }

    if (o.type() == osmium::item_type::way) {
        if (roads) {
            *roads = (int)lua_tointeger(L, -1);
        }
        lua_pop(L, 1);
        if (polygon) {
            *polygon = (int)lua_tointeger(L, -1);
        }
        lua_pop(L, 1);
    }

    lua_pushnil(L);
    while (lua_next(L, -2) != 0) {
        const char *key = lua_tostring(L, -2);
        const char *value = lua_tostring(L, -1);
        out_tags.emplace_back(key, value);
        lua_pop(L, 1);
    }

    bool filter = lua_tointeger(L, -2);

    lua_pop(L, 2);

    return filter;
}
 bool matches_user_filter(const osmium::OSMObject& obj) {
     if (obj.user_is_anonymous()) return false;
     std::unordered_set<osmium::user_id_type>::const_iterator it = m_filter_users.find(obj.uid());
     if (it == m_filter_users.end()) return false;
     return true;
 }
Пример #26
0
 const osmium::Timestamp end_time() const {
     return last() ? osmium::Timestamp() : m_next->timestamp();
 }
Пример #27
0
 osmium::item_type type() const noexcept {
     return m_curr->type();
 }
Пример #28
0
 osmium::changeset_id_type changeset() const noexcept {
     return m_curr->changeset();
 }
Пример #29
0
void gazetteer_style_t::process_tags(osmium::OSMObject const &o)
{
    clear();

    char const *postcode = nullptr;
    char const *country = nullptr;
    char const *place = nullptr;
    flag_t place_flag;
    bool address_point = false;
    bool interpolation = false;
    bool admin_boundary = false;
    bool postcode_fallback = false;

    for (auto const &item : o.tags()) {
        char const *k = item.key();
        char const *v = item.value();

        if (strcmp(k, "admin_level") == 0) {
            m_admin_level = atoi(v);
            if (m_admin_level <= 0 || m_admin_level > MAX_ADMINLEVEL)
                m_admin_level = MAX_ADMINLEVEL;
            continue;
        }

        if (m_any_operator_matches && strcmp(k, "operator") == 0) {
            m_operator = v;
        }

        flag_t flag = find_flag(k, v);

        if (flag == 0) {
            continue;
        }

        if (flag & SF_MAIN) {
            if (strcmp(k, "place") == 0) {
                place = v;
                place_flag = flag;
            } else {
                m_main.emplace_back(k, v, flag);
                if ((flag & SF_BOUNDARY) && strcmp(v, "administrative") == 0) {
                    admin_boundary = true;
                }
            }
        }

        if (flag & (SF_NAME | SF_REF)) {
            m_names.emplace_back(k, v);
            if (flag & SF_NAME) {
                m_is_named = true;
            }
        }

        if (flag & SF_ADDRESS) {
            char const *addr_key;
            if (strncmp(k, "addr:", 5) == 0) {
                addr_key = k + 5;
            } else if (strncmp(k, "is_in:", 6) == 0) {
                addr_key = k + 6;
            } else {
                addr_key = k;
            }

            if (strcmp(addr_key, "postcode") == 0) {
                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);
                }
            }
        }

        if (flag & SF_ADDRESS_POINT) {
            address_point = true;
            m_is_named = true;
        }

        if ((flag & SF_POSTCODE) && !postcode) {
            postcode = v;
            if (flag & SF_MAIN_FALLBACK) {
                postcode_fallback = true;
            }
        }

        if ((flag & SF_COUNTRY) && !country && std::strlen(v) == 2) {
            country = v;
        }

        if (flag & SF_EXTRA) {
            m_extra.emplace_back(k, v);
        }

        if (flag & SF_INTERPOLATION) {
            m_main.emplace_back("place", "houses", SF_MAIN);
            interpolation = true;
        }
    }

    if (postcode) {
        m_address.emplace_back("postcode", postcode);
    }
    if (country) {
        m_address.emplace_back("country", country);
    }
    if (place) {
        if (interpolation || (admin_boundary &&
                              strncmp(place, "isl", 3) != 0)) // island or islet
            m_extra.emplace_back("place", place);
        else
            m_main.emplace_back("place", place, place_flag);
    }
    if (address_point) {
        m_main.emplace_back("place", "house", SF_MAIN | SF_MAIN_FALLBACK);
    } else if (postcode_fallback && postcode) {
        m_main.emplace_back("place", "postcode", SF_MAIN | SF_MAIN_FALLBACK);
    }
}