Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug (?): WayRefIter first and last node has the same node ID #44

Open
OlleDelborg opened this issue Mar 25, 2024 · 3 comments
Open

Bug (?): WayRefIter first and last node has the same node ID #44

OlleDelborg opened this issue Mar 25, 2024 · 3 comments

Comments

@OlleDelborg
Copy link

OlleDelborg commented Mar 25, 2024

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();
}

@b-r-u
Copy link
Owner

b-r-u commented Mar 25, 2024

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 :)

@OlleDelborg
Copy link
Author

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

@b-r-u
Copy link
Owner

b-r-u commented Mar 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants