Repository navigation
Road Elevation Smoothing - #1220
Conversation
|
I just tried to apply a LOESS regression instead of a "simple average" approach. For most cases this produced comparable or slightly better results than the average function, but sometimes it completely failed resulting in elevation values of 0, for example for this route, I just commited it so that interested users could try this approach or maybe there is some room for tuning the LoessInterpolator? Unless we find a way to fix these issues, I would remove the Loess approach for the final PR again. BTW: I removed the LOESS approach in 0d0c685. If anyone wants to try it out, have a look at cdab456. |
|
I updated this PR to also smooth the Tower Nodes, I am not 100% sure yet, if this is a good thing to do or not. Most cases improved due to that, but a few became worse. Maybe it might be better to use a high precision elevation data source and only smooth pillar nodes? |
|
I updated this PR. The smoothing happens now in the OSMReader. For two reasons:
Currently it is designed as an "opt-in" feature, so you have to specify |
|
Cool, thanks! So it is no longer a WIP? |
I need to go through the code one more time. It is working, I just want to clean up a couple of minor things and need to fix some tests, etc. Feel free to try it though :). I think it should be ready for review tomorrow 👍. |
I updated and cleaned up this PR. I think this should be good to merge now. |
| public DataReader setSmoothElevation(boolean smoothElevation) { | ||
| // TODO implement elevation smoothing for shape files | ||
| return this; | ||
| } |
There was a problem hiding this comment.
Do we need elevation smoothing for shape files?
| private final static int MAX_SEARCH_DISTANCE = 180; | ||
|
|
||
| public static PointList smoothElevation(PointList geometry) { | ||
| if (geometry.size() >= MIN_GEOMETRY_SIZE) { |
There was a problem hiding this comment.
we do not need check this IMO due to i=1 and i<size-1
There was a problem hiding this comment.
Yes true, I had it there because I was experimenting with different min geometry sizes to see if there is a difference. Also when I played with the LOESS regression, this required at least 7? points to work.
| for (int i = 1; i < geometry.size() - 1; i++) { | ||
| int start = i - MAX_SEARCH_RADIUS < 0 ? 0 : i - MAX_SEARCH_RADIUS; | ||
| // +1 because we check for "< end" | ||
| int end = i + MAX_SEARCH_RADIUS + 1 >= geometry.size() ? geometry.size() : i + MAX_SEARCH_RADIUS + 1; |
There was a problem hiding this comment.
Why is this MAX_SEARCH_RADIUS necessary additionally to MAX_SEARCH_DISTANCE?
(also naming should be like MAX_NODES or something)
There was a problem hiding this comment.
Points are not evenly scattered. For highways one point might be far away. You are right about the naming, I will improve this, thanks.
There was a problem hiding this comment.
But isn't the search distance the only thing we want?
There was a problem hiding this comment.
But isn't the search distance the only thing we want?
Good point :). I will have to try and compare the results 👍.
There was a problem hiding this comment.
I did that. I think this makes indeed more sense. Overall the differences weren't huge in my tests. I think we might need to improve this over time if we find cases where the smoothing is not ideal.
| for (int j = start; j < end; j++) { | ||
| // We skip points that are too far away, important for motorways | ||
| if (MAX_SEARCH_DISTANCE > Helper.DIST_PLANE.calcDist(geometry.getLat(i), geometry.getLon(i), geometry.getLat(j), geometry.getLon(j))) { | ||
| sum += geometry.getEle(j); |
There was a problem hiding this comment.
We could even let the distance influence the average: https://en.wikipedia.org/wiki/Weighted_arithmetic_mean
There was a problem hiding this comment.
What I tried so far was to weight closer points as more important. This made the results worse, see my comment (copied it below). What we could try is to weight closer points with a lower weight. But this sounds wrong to me, but I could try it if you think this would make sense?
I am not sure if it would be better to rate points that are farther away with a lower weight? I tried this briefly and this led to worse results. Probably because outliers will have a greater impact.
There was a problem hiding this comment.
Ah, ok. Did you apply the changed formula ala (x*ele1+y*ele2)/(x+y)?
There was a problem hiding this comment.
Yes, but I didn't use the actual distance from the points but onĺy the array index. I can do more experiments using the weighted arithmetic mean if you want?
|
|
||
| // elevation | ||
| String eleProviderStr = args.get("graph.elevation.provider", "noop").toLowerCase(); | ||
| this.smoothElevation = args.getBool("graph.elevation.smooth_elevation", false); |
There was a problem hiding this comment.
I'd slightly prefer to avoid "elevation" wording duplication and instead use graph.elevation.smoothing?
There was a problem hiding this comment.
Yes makes sense, I will change this :).
|
There seems to be a test failure (or is this unrelated?) GraphHopperWebIT.testRetrieveOnlyStreetname:123 expected:<[Turn right onto B 24]6> but was:<[Continue onto B 9]6> |
This seems to be unrelated, but I fixed it anyway. The routing on the server changed (maybe some OSM data changed?), not sure why, but the route looks OK to me. |
|
Ah, ok. Didn't notice we are testing here against the server - thanks! |
This PR fixes/approaches #517.
The problem with GH currently is that the elevation data contains spikes and the overall calculated ascend and descend are sometimes wrong by a factor of two or more.
Because of the increased calculation of ascend and descend, the distance can be wrong as well, because GH calculates the distance of a road using lat, lon, and elevation.
This PR proposes a rather simple approach. Before adding an edge to the graph, we smooth it's elevation, removing most spikes. Take the geometry of the edge and for every "pillar" but not "tower" node of the geometry, look at the surrounding points and calculate the average of these points.
TODO:
I am not sure if it would be better to rate points that are farther away with a lower weight?I tried this briefly and this led to worse results. Probably because outliers will have a greater impact.Here are some comparisons:
Schauinsland

GH Maps 29.46km ↗1891m ↘1515m
PR 28.96km ↗1208m ↘828m

Google Maps 28.0km ↗902m ↘542m

From Grabenstetten to St. Johan.
GH Maps 15.72km ↗907m ↘863m

PR 15.37km ↗491m ↘446m

Google Maps 15.3 km ↗328m ↘277m

Neuffen.
GH Maps 5.15km ↗613m ↘332m

PR 4.86km ↗360m ↘82m

Google Maps 4.8km ↗293m ↘14m

I also tried routes #330 and #533. It seems like both issues are already fixed because there has been a CGIAR data update recently. However I showed how the smoothing works in these cases with a screenshot below.
Routes from #330.


Herrnstein
Routes from #553.
Bad Hindelang

