osmcode / libosmium

Fast and flexible C++ library for working with OpenStreetMap data.
https://osmcode.org/libosmium/
Boost Software License 1.0
467 stars 113 forks source link

Iterating over osmium::index::map::FlexMem<TKey, TValue>. #297

Closed gorishaa9 closed 4 years ago

gorishaa9 commented 4 years ago

Hi,

This may be a naive question and I may have missed something. But how do we iterator over the unique set of key-value pairs in osmium::index::map::FlexMem<TKey, TValue>? It does not have .begin() and .end() as its members.

Also, I was looking for something like, given a node id, I can get the osmium::Node& object. I know I cannot use a map to index by the node ids since it will consume a lot of memory. Is there any other way I can do this?

Any help will be greatly appreciated.

Thanks.

joto commented 4 years ago

But how do we iterator over the unique set of key-value pairs in osmium::index::map::FlexMem<TKey, TValue>?

There is no way to iterate over these. Implementing that isn't totally straightforward because of the internal structure of that container, so I never implemented it. Also, of course, because I never saw the need.

Also, I was looking for something like, given a node id, I can get the osmium::Node& object.

The most common solutions are:

  1. read the file twice, on the first run store the node ids you need somewhere, on the second run pick out the nodes
  2. use an ObjectPointerCollection

If you tell us what you want to achieve we can probably help you more.

gorishaa9 commented 4 years ago

Ohh, I see.

For the second task, I thought about the first solution you suggested. That will work.

Otherwise, in general, I am planning to flag some specific nodes appearing in the ways. I wish to break the "way" into smaller "segments" formed from these flagged nodes. I plan to store these segments, as a struct of two consecutive flagged nodes (denoting the starting and end point of the segment). I then want to build an R*-tree out of these segments.

Also, I know we can iterate over osmium::OSMObject objects in osmium::ObjectPointerCollection object. Is there no way to get the OSMObject object in osmium::ObjectPointerCollection object by the position of the object as the index? Like the way we do in array? I would need something to get an OSMObject object by their id.

Thank you for your time and help.