Skip to content

Improve resolution of elevation profiles with 3D Douglas Peucker and long edge sampling - #1953

Merged
karussell merged 64 commits into
graphhopper:masterfrom
msbarry:sample-and-3d-simplify
Jun 11, 2020
Merged

karussell merged 64 commits into
graphhopper:masterfrom
msbarry:sample-and-3d-simplify

Conversation

@msbarry

@msbarry msbarry commented Mar 13, 2020 •

Copy link
Copy Markdown
Contributor

Improve the resolution of elevation profiles by:

  1. sampling points along long edges so we don't miss elevation changes over that segment
  2. making Douglas Peucker polyline simplification elevation-aware so it keeps points that only impact the elevation profile and not the 2D shape

These options have the potential to increase geometry size, so I added 2 configuration options to control them:

  1. graph.elevation.long_edge_sampling_distance which defines the distance in meters that it will sample points along long edges, for example you might set this to somewhere around 30m if your elevation provider has 30m resolution. It defaults to 0 which disables long edge sampling.
  2. graph.elevation.way_point_max_distance which defines the elevation tolerance during polyline simplification, for example with a 1m lat/lon and elevation tolerance removes points that result in a <1m shift of the 3D polyline. It defaults to Double.MAX_VALUE which disables elevation-influenced simplification.

Edge Geometry Size Increase

I ran this code on north-america_us_pennsylvania.pbf with CGIAR and bilinear interpolation with different values of those parameters and saw these edge geometry size increases over what's on master now:

sampling distance ➡️
elevation max distance ⬇️ 
15m 30m 45m 60m 100m 500m off (∞)
1m 19% 17% 17% 15% 11% 6% 6%
1.5m 11% 11% 9% 9% 6% 2% 2%
2m 6% 6% 6% 6% 4% 2% 2%
3m 2% 2% 2% 2% 2% 0% 0%
4m 2% 2% 2% 2% 0% 0% 0%
5m 0% 0% 0% 0% 0% 0% 0%
10m 0% 0% 0% 0% 0% 0% 0%
50m 0% 0% 0% 0% 0% 0% 0%
off (∞) 0% 0% 0% 0% 0% 0% 0%

I ran the same test with mapzen/skadi provider from #1929. Results were similar, but the increase was slightly larger (26% instead of 19% for 15m/1m) probably because of the higher resolution of the underlying data.

Import time performance

I observed the "pass2" time during import. There was no change for different values of the elevation factor, but shorter long edge sampling distances did increase that time by 25% for 15m, 9% for 30m, 8% for 45m, and <2% for longer distances. Last time I imported the world pass2 took 110 minutes, so even a 25% increase is only about a 28 minute increase which seems negligible to me.

Examples

This 2km straight segment loses all elevation details on master
image

but with 30m edge sampling and 1m elevation resolution we get that elevation detail back:
image

Let me know if there are other examples or different values of the 2 parameters you want to see.

See further discussion here

@karussell karussell left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for this! Especially the effort to show the impact of the size with the different parameters. This makes it really easy for us to try it out and get it merged faster.

@msbarry

msbarry commented May 15, 2020

Copy link
Copy Markdown
Contributor Author

How about we go with:

  graph.elevation.long_edge_sampling_distance: 60
  graph.elevation.way_point_max_distance: 10

These would be configurable anyway, but results for these look good straight away if anyone wants to activate this feature. WDYT?

Sounds good to me, I set those default values in the comments in config-example.yml.

That is actually quite an interesting find. Do you know why this could happen? Maybe the contour lines are approximated already? Therefore, it might not be possible to fully trust them?

Might be caused by the interpolation in the elevation provider. @msbarry you could try to disable it for your tests

I don't think it's an issue sampling the actual DEM file since this based on where the samples are located, there should be enough resolution to separate the river from the hill around that curve
image

It's probably an irregularity with the DEM data provider. According to https://github.com/tilezen/joerd/blob/master/docs/data-sources.md, skadi uses EU-DEM for most of Europe which is "a hybrid product based on SRTM and ASTER GDEM data fused by a weighted averaging approach." So it could be artifacts from either in the SRTM/ASTER -> EU-DEM conversion or EU-DEM to skadi conversion.

@msbarry

msbarry commented May 19, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the review @boldtrn! @karussell any more changes you want me to make here?

@msbarry

msbarry commented Jun 1, 2020

Copy link
Copy Markdown
Contributor Author

Congrats on the 1.0 release! Think this might be safe to merge soon @karussell ?

@karussell karussell added this to the 2.0 milestone Jun 9, 2020
@karussell

karussell commented Jun 9, 2020 •

Copy link
Copy Markdown
Member

Thanks a lot @msbarry for your work here! Also thanks @boldtrn for the review!

If I understand it correctly an existing application is not affected or will it be affected if it already uses interpolation?

@karussell

karussell commented Jun 9, 2020 •

Copy link
Copy Markdown
Member

@otbutz (I'm unsure if my reply above was after your edits or before)

Are there any side effects for the existing elevation interpolation used for bridges and tunnels?

I don't think so. Basically what we do for bridges and tunnels is to get rid of elevation.

Edit: if i'm not mistaken, we interpolate elevation at three different locations now?

Yes, but at least the bridge/tunnel part is a different purpose.

@msbarry

msbarry commented Jun 10, 2020

Copy link
Copy Markdown
Contributor Author

As I understand it correctly an existing application is not affected or will it be affected if it already uses interpolation?

Yes, existing applications should not be affected whether they use bilinear interpolation or not since the 2 new config parameters default to Double.MAX_VALUE which retains existing behavior.

@karussell

karussell commented Jun 10, 2020 •

Copy link
Copy Markdown
Member

Ok, thanks for confirming.

Now I also better understand your images in #1953 (comment), i.e. red is the only area where the incline and decline increase ("got worse"). So this PR with the proposed settings in config-example.yml is always an improvement and should decrease incline&decline? (over CGIAR and interpolation only)

setElevationProvider(eleProvider).
setWorkerThreads(dataReaderWorkerThreads).
setWayPointMaxDistance(dataReaderWayPointMaxDistance).
setWayPointElevationMaxDistance(elevationWayPointMaxDistance).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@easbar probably a matter of taste but ... there are properties that are used while import and for the routing and they could be different which would motivate two variables, but likely not here. Should we still keep the two variables?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could also make elevation way point max distance controllable through a request parameter for routing?

@easbar easbar Jun 11, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for this very nice PR @msbarry!

As far as I can tell the elevationWayPointMaxDistance is used to control how many extra pillar nodes get created during import (to preserve elevation changes within the geometries) and it is also used during path simplification when running routing requests (to not throw away way points reflecting elevation changes). These two usages are different in that the first only can have an effect during import (after the first import it becomes meaningless unless we rebuild the graph) while the other could (at least in theory) be changed for every single request. Is that correct? For this reason I think it would be cleaner to use two parameters, e.g. one would go into the (not yet existing) ImporterConfig and the other would go to RouterConfig and the latter could also be changed via the routing hints in Router#createPathMerger. I just wonder if this is overkill and I do not think its urgent to separate this into two parameters already. In any case the parameter used for the import is a good default value for the one used during routing?

Should we still keep the two variables?

Which two variables do you mean? I thought so far there is only one (only one that has to do with import and routing).

We could also make elevation way point max distance controllable through a request parameter for routing?

Yes, exactly, in Router#createPathMerger.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @easbar, longEdgeSamplingDistance controls how many extra pillar nodes are added and elevationWayPointMaxDistance prevents them from getting removed during simplification (on import, and during routing). I added a new elevation_way_point_max_distance request parameter in 9edbfbf to let you change elevationWayPointMaxDistance on each request or omit to default to what was used during import. I agree it's probably overkill to split out separate config parameters for data reader import and router default. Let me know if that change looks sufficient.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes thanks I like it.

@msbarry

msbarry commented Jun 11, 2020

Copy link
Copy Markdown
Contributor Author

Now I also better understand your images in #1953 (comment), i.e. red is the only area where the incline and decline increase ("got worse"). So this PR with the proposed settings in config-example.yml is always an improvement and should decrease incline&decline? (over CGIAR and interpolation only)

Those charts show increase/decrease relative to CGIAR without interpolation. 10m/60m plus bilinear interpolation proposed in config-example.yml should report an "improvement" with less total elevation gain/loss than people are used to with CGIAR and no interpolation today.

@karussell
karussell merged commit 699043f into graphhopper:master Jun 11, 2020
@karussell

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants