Bug (?): WayRefIter first and last node has the same node ID
When iterating over the references of nodes in a way the first and last node id reference has the same id, in almost all ways (there are exceptions, but they are in the minority). I've tried this on a couple of different data sets but it yields the same result. Based on my knowledge on the structure of OSM this should not happen, but if I'm mistaken then please let me know. I've posted a basic function to replicate the issue.
fn iter_ways() { let reader = ElementReader::from_path("path/to/file").unwrap(); reader .for_each(|element| if let Element::Way(way) = element { let mut it: WayRefIter<'_> = way.refs(); let first_node_in_way: i64 = it.next().unwrap(); let last_node_in_way: i64 = it.last().unwrap(); println!("first: {first_node_in_way}, last: {last_node_in_way}"); // both are equal }) .unwrap(); }
Thanks for this issue! A lot of OSM ways actually represent polygons (e.g., buildings) by specifying a closed way where the first and last node are identical: https://wiki.openstreetmap.org/wiki/Way#Closed_way_(closed_polyline)
So this is intended and you are not experiencing a bug in this case :)
Yes, of course! I had forgotten about the closed polyline objects :) An additional question though, what would be the best way to filter out ways based on tags in the above example, I know that I can use the tags(), but I haven't found an easy way of how to filter out highway nodes and then retrieving node ID's (and preferably node locations). Perhaps this is quite trivial, however I'm quite new to rust as well as this crate.
Thanks
You should try using IndexedReader::read_ways_and_deps if you want to filter ways and also get the corresponding nodes:
https://docs.rs/osmpbf/0.3.3/osmpbf/indexed/struct.IndexedReader.html#method.read_ways_and_deps