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

fix graphbuilder's elevation initialization #3571

Merged
merged 12 commits into from
Mar 22, 2022
Merged

Conversation

nilsnolde
Copy link
Member

fixes #3258

finally getting some time to fix some of my old issues..

mostly fixes returning "mean_elevation": null when there is none, instead of 1234. also some others:

EdgeInfo::json was casting elevation to an unsigned integer, leading to bogus values for the (admittedly few) roads which are sub sea level, e.g. next to dead sea:

curl --request POST \
  --url https://valhalla1.openstreetmap.de/locate \
  --header 'Content-Type: application/json' \
  --data '{
	"costing": "auto",
	"verbose": true,
	"id": 1,
	"locations": [
		{
			"lon": 35.408936,
			"lat": 31.591404
		}
	]
}'

leads to "mean_elevation": 18446744073709551254. with this PR it's "mean_elevation": -362.

…ed mean_elevation to unsigned integer for /locate response leading to bogus values
@@ -24,10 +24,10 @@ void EdgeInfoBuilder::set_wayid(const uint64_t wayid) {

// Set the mean elevation.
void EdgeInfoBuilder::set_mean_elevation(const float mean_elev) {
if (mean_elev < kMinElevation) {
if (mean_elev <= kNoElevationData) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I got rid of the kMinElevation as it's now the same value as kNoElevationData. let me know if you want to keep it for semantics

Copy link
Member

Choose a reason for hiding this comment

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

isnt it the case that we need to differentiate between no data and minimum value though? like when its no data then we serialize null and when its minimum value we serialize the minimum value, right?

Copy link
Member Author

@nilsnolde nilsnolde Mar 17, 2022

Choose a reason for hiding this comment

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

Minimum value (-500) will not be serialized, same as no data. Think that’s fine, there’s really no place on terrestrial earth at -500. Dead Sea depression is at -450 or so, roads near that have the lowest values in the world. What do you think @kevinkreiser ? Since it's only for enriching the graph where we only look at roads, the /height endpoint won't be affected.

Copy link
Member

Choose a reason for hiding this comment

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

yeah you are saying in practice -500 wont happen so no_data can be the same as min_value but like you mentioned at the beginning it does seem a bit semantically strange in the computation later where you do an offset by the no data value. i'd be happy just duplicating the constant even if they were the same value so that when you read the code you offset by the min-value rather than the no-data-value

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah true, wasn't very happy with that either but with the comment above the constant in graphconstants I found it ok-ish.. then let me duplicate that constant

Copy link
Member Author

Choose a reason for hiding this comment

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

reverted the change to edgeinfo.h where kMinElevation was set before, which reverted all changes to edgeinfo.h and edgeinfobuilder.h. kMinElevation is now used where appropriate

is the internet broken today?! github is being ridiculously slow or doesn't respond at all after pushing, geofabrik same, curl actually times out downloading some pbf.. maybe it's telling me to go home instead..

Copy link
Member Author

Choose a reason for hiding this comment

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

case in point:

To github.com:gis-ops/docker-valhalla.git
 ! [remote rejected] master -> master (Internal Server Error)
error: failed to push some refs to 'github.com:gis-ops/docker-valhalla.git'

first time ever for me

(*nodes[target]).graph_id, w.way_id(), 1234, bike_network,
speed_limit, shape, names, tagged_values, pronunciations, types,
added, dual_refs);
(*nodes[target]).graph_id, w.way_id(), kNoElevationData,
Copy link
Member Author

Choose a reason for hiding this comment

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

so I changed it from 0 to the no data value, which will return null in the geojson response. I traced all usages of mean_elevation & co and can't see how this change would affect anything negatively

} else {
trip_edge->set_mean_elevation(kNoElevationData);
}
trip_edge->set_mean_elevation(edgeinfo.mean_elevation());
Copy link
Member Author

Choose a reason for hiding this comment

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

this was redundant for elevation. the set_mean_elevation will handle the case when there's no elevation set

Copy link
Member

Choose a reason for hiding this comment

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

its redundant now that you fixed it! it wasnt redundant in the past, previously this protected us from getting 1234 in the response

valhalla/baldr/edgeinfo.h Outdated Show resolved Hide resolved
@nilsnolde nilsnolde requested a review from kevinkreiser March 16, 2022 13:40
src/skadi/util.cc Outdated Show resolved Hide resolved
…lue from skadi and convert to -500 in mjolnir
src/skadi/util.cc Outdated Show resolved Hide resolved
src/skadi/util.cc Outdated Show resolved Hide resolved
src/skadi/util.cc Outdated Show resolved Hide resolved
@nilsnolde nilsnolde requested a review from kevinkreiser March 17, 2022 14:23
@nilsnolde
Copy link
Member Author

the osx build finished, it was triggered when github had their outages. probably the reason why win never started?

@nilsnolde
Copy link
Member Author

fixed up the last minor things @kevinkreiser . thanks for the review

@nilsnolde nilsnolde merged commit 6e28861 into master Mar 22, 2022
@nilsnolde nilsnolde deleted the nn-fix-elevation-1234 branch March 22, 2022 17:39
Comment on lines +136 to +138
edge_map->emplace("mean_elevation", static_cast<int64_t>(options.units() == Options::miles
? mean
: mean * kFeetPerMeter));
Copy link
Contributor

@christian-nils christian-nils Mar 29, 2022

Choose a reason for hiding this comment

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

@nilsnolde, it seems that the "inline if" is not correct here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
edge_map->emplace("mean_elevation", static_cast<int64_t>(options.units() == Options::miles
? mean
: mean * kFeetPerMeter));
edge_map->emplace("mean_elevation", static_cast<int64_t>(options.units() == Options::miles
? mean * kFeetPerMeter
: mean ));

Copy link
Member

@kevinkreiser kevinkreiser Mar 29, 2022

Choose a reason for hiding this comment

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

wow oops, i missed that. thanks for the catch and ill take care of that!

kevinkreiser added a commit that referenced this pull request Mar 29, 2022
kevinkreiser added a commit that referenced this pull request Mar 29, 2022
Co-authored-by: Christian-Nils Åkerberg Boda <[email protected]>

Co-authored-by: Christian-Nils Åkerberg Boda <[email protected]>
DmitryAk added a commit to DmitryAk/valhalla that referenced this pull request Sep 7, 2022
@DmitryAk DmitryAk mentioned this pull request Sep 7, 2022
1 task
kevinkreiser pushed a commit that referenced this pull request Sep 7, 2022
* Fix in addition to #3571

* Update changelog
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.

mean_elevation for EdgeInfo is initialized with 1234 m
3 participants