OpenStreetMap Forum

The Free Wiki World Map

You are not logged in.

#1 2019-03-13 21:46:18

utack
Member
Registered: 2016-02-07
Posts: 64

Osmium: Copy a way inside a handler

Edit/Solved:
Mr. Topf, the creator of libosmium, was generous enouh to explain why the first thing does not work.
osmium always operates with a buffer, and the buffer is destroyed once the handler is done



Hi forum,

I am currently trying to store a copy of a way inside a simple osmium handler that I am applying to an input file
Could you please help me to achieve this correctly, because this does not work

class StreetHandler : public osmium::handler::Handler {
	void way(const osmium::Way& way) {
		osmium::Way currentStreet = way;
	}
};

What I would need is to create something of type "osmium::Way" and copy the input way the handler gives me into it

According to the docs OSM objects always need to be created in a buffer:
https://osmcode.org/libosmium/manual.html#buffers
However this leaves me with another problem: How do I "extract" my osmium::Way from this buffer once I have it?

class StreetHandler : public osmium::handler::Handler {
void way(const osmium::Way& way) {
		osmium::memory::Buffer m_buffer{1024, osmium::memory::Buffer::auto_grow::yes};
		osmium::builder::WayBuilder builder{m_buffer};
		builder.add_item(way.nodes());
		m_buffer.commit();
};

This buffer should contain a way with the same nodes as the input way had them.
However *m_buffer.begin() is a general "osmium::OSMEntity", not an "osmium::Way"


I hope you can shed some light on what I am missing.
Thank you!

Last edited by utack (2019-03-15 01:28:38)

Offline

Board footer

Powered by FluxBB