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

Allow empty elevation tags #72

Merged
merged 4 commits into from
May 27, 2022
Merged

Allow empty elevation tags #72

merged 4 commits into from
May 27, 2022

Conversation

ebcrowder
Copy link
Contributor

@ebcrowder ebcrowder commented May 26, 2022

Similar to #70, I have a GPX file that has self-closing elevation tags, which of course, contain no value. This appears to be valid per the GPX spec at https://www.topografix.com/GPX/1/1/#type_ptType.

The GPX file was generated by a Wahoo bike computer.

This change edits the parsing logic to use a default f64 value of 0.00 for these cases. I didn't see a precedence for handling similar optional values in this lib, so let me know if I should handle this differently in accordance with the project's goals.

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGELOG.md if knowledge of this change could be valuable to users.

@urschrei
Copy link
Member

If I'm understanding this change correctly, wouldn't that result in spurious elevation values of 0.0? Unless I'm misunderstanding the spec (and I may well be), we should parse then discard empty elevation tags – they don't represent any useful information. I should qualify my opinion by noting that I haven't done much work with GPX, so very happy to be corrected here.

for segment in &track.segments {
for point in &segment.points {
// Elevation should default to 0.00
let elevation = point.elevation.unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd expect point.elevation.is_none() here

@ebcrowder
Copy link
Contributor Author

If I'm understanding this change correctly, wouldn't that result in spurious elevation values of 0.0? Unless I'm misunderstanding the spec (and I may well be), we should parse then discard empty elevation tags – they don't represent any useful information. I should qualify my opinion by noting that I haven't done much work with GPX, so very happy to be corrected here.

Yes! Good point. 0.00 would be a valid elevation value, so defaulting to that would not be a good approach. I will rework this to parse and discard those tags.

@michaelkirk
Copy link
Member

If you haven't seen it already - I think you could match on the Err(GpxError::NoStringContent) case returned from string::consume(context, "ele", false)

@michaelkirk
Copy link
Member

Also, thanks for having tests - it makes the PR easier to review when we can see the new behavior in action. 👍

@ebcrowder
Copy link
Contributor Author

ebcrowder commented May 27, 2022

@michaelkirk @urschrei thanks for the feedback. I made those edits.

Even though they don't explicitly cover this change, I did maintain the additional tests at src/parser/string.rs since I think they provide some additional clarity of the string parsing behavior. I'd be happy to remove them if you prefer, though.

@urschrei
Copy link
Member

I'm happy for them to stay in. If you could update the changelog (you'll need to pull master first since we've merged some changes) we'll get this merged today and push out a bugfix release, since this is the second spec-related bug that's been fixed.

@urschrei
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request May 27, 2022
72: Allow empty elevation tags r=urschrei a=ebcrowder

Similar to #70, I have a GPX file that has self-closing `elevation` tags, which of course, contain no value. This appears to be valid per the GPX spec at https://www.topografix.com/GPX/1/1/#type_ptType.

The GPX file was generated by a Wahoo bike computer.

This change edits the parsing logic to use a default `f64` value of `0.00` for these cases. I didn't see a precedence for handling similar optional values in this lib, so let me know if I should handle this differently in accordance with the project's goals. 

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGELOG.md` if knowledge of this change could be valuable to users.
---



Co-authored-by: Eric Crowder <eric@ebcrowder.dev>
waypoint.elevation = Some(string::consume(context, "ele", false)?.parse()?)
waypoint.elevation = match string::consume(context, "ele", false) {
Ok(v) => Some(v.parse()?),
Err(_) => None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't there other errors that we'd want to surface here? I think the only error we'd want to map to None is GpxError::NoStringContent

Err(GpxError::NoStringContent) => None,
Err(other_err) => return Err(other_err)

For example, I think we'd want an element like this to continue to error, not return None:

<ele>1.asdf</ele>

@urschrei
Copy link
Member

bors r-

@michaelkirk
Copy link
Member

bors r-

(sorry!)

@bors
Copy link
Contributor

bors bot commented May 27, 2022

Canceled.

@michaelkirk
Copy link
Member

bors r+

@bors
Copy link
Contributor

bors bot commented May 27, 2022

Build succeeded:

@bors bors bot merged commit ee2bdf2 into georust:master May 27, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants