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
Using external data (elevation, polution, traffic...) in lua profiles #546
Comments
|
I am very interested on this feature too, I want to include traffic data, anyone knows how to support it? |
|
i think traffic data comes in several flavours: statstical data about traffic amounts, roadwords, and situational data about congestion, accidents, etc. osrm is probably less well suited to handle situational data, since osrm can only process the entire dataset, not local areas. if you're working with a large area, this in impractical or impossible. but roadworks, statistical data and other semi-static data could well be handled, there's just no way yet to do it. we need a system where the lua profiles can access the data when processing each way segment. |
|
If segment processing using elevation data works, one could do the same with other raster data. |
|
elevation might be special, since it causes speed/cost to be different for each direction of a segment? |
|
Emil Tin notifications@github.com writes:
well yes, but you can of course just return the same value for both see also: |
|
if i understand your code correctly, your approach to elevation is:
wouldn't it be much faster if osrm had a c++ utility to sample a raster file on disk? using http to query every node must incur a lot of overhead. |
|
Emil Tin notifications@github.com writes:
it isn't called twice anymore it is called once
there are 2 implementations of the same api:
the elevation profile service has some features i don't want to miss
for me the bigger question is the overall approach - especially wether Slow parts can be improved / replaced / have alternative implementations |
|
edited last comment because i refered to "above" (i answered by mail and thought it was a different issue) |
|
i agree that it's important to figure out the osrm internals. |
|
Emil Tin notifications@github.com writes:
for me the most important point is: |
|
hello. i think pre-generate the elevation data would be a good idea. you can download various elevation sources (e.g. ciat/cgiar - viewfinder_parnoramo). to combine these datasources into small binary tiles i have made a perl-script: this script first creates Arc/Info ASCII files (because gdal has no ArcGis binary write support), and convert these files into binary files. each file holds data for a 1x1 degree tile (3600x3600 elevation values (eg. every 30m)). each file has about 25MB. so europe needs around 100GB and the world 1TB. max |
|
i'm sure @DennisOSRM can say more about this, but i would think that performance will be limited by disk access, since such a huge dataset cannot be kept in ram. how efficient are archgis binary files when it comes to file size and speed of random access? |
|
@ prozessor13 how many of these elavation tiles do you end up with? |
|
i think the performance will be very good, because: i would keep (may) the last used 5 or 10 tiles in RAM, and i think there will be a lot of requests to the same tile before another one is needed (because the edge data is sorted in the osrm array). i saw, dennis had alredy programmed some nasagrid code in OSRM (in c++), and this code works very simmilar. my intention for this logic ist:
drawback of implementing this in lua instead of C++ is maybe the speed, and that i dont know how to implement an library which will be shared over all the parsing threads. pseudocode would something like this: ps: europe needs exactly 65GB and 2501 files |
|
but actually you would only need to store elevation for node locations, not all the other possible locations? maybe osrm could just cache those when they're requested from an external service. this should be far less data that the entire elevation map? |
|
@karme regarding segment vs edge vs way-based processing - i might not be entirely clear about the distinctions, but - at least i think we need two values for each way, to handle uphill/downhill. btw this is also needed to handle pushing bikes against oneways streets, since this means you have different speeds in each direction. segment vs. edge - i suppose the question here is that each edge between two nodes can consist of several segments, and we could either process each segment, or only the edge? |
|
max wukits notifications@github.com writes:
those are not really free datasets i have put together a stack of free datasets here: |
|
Emil Tin notifications@github.com writes:
with segment i mean a line segment between 2 osm nodes
ack
yes there are of course much less edges than segments the other reason to think into that direction is what i meant with if you seperate the processing into a way and segment stage, you often |
|
osrm routing is edge-based, and i suppose changing this is not an option. if we process edges in lua, we have only the elevation of the end points, and thus the difference. if we process segments, we also know how it's going uphill/downhill between the crossing. a parallel use case of working with segments would be to prefer straight roads over winding roads. perhaps it would be possible to only process edges, not segments, but then in addition sample elevation of the start and end points, since they're usually somewhere in the middle of an edge. anthor idea - what about processing each edge by providing lua with an array of the segments it contains? (@karme, i didn't yet look into your code, is this what you do?) |
|
Emil Tin notifications@github.com writes:
it uses the segments as edges no?
at the moment i do upsample the segments anyway if the processing would be edged based (where the edges are polylines
hmm - maybe we still mean different things? in my view this would be another case for working with polyline-based another one:
ack
don't understand
really looks like we use the same words with differnt meanings :( but yes, the idea was to use only nodes and polyline-based edges in the this doesn't mean that the osrm routing must use polylines as edges |
|
i think you got a point. i've added a wiki page to try to get a common definition of these concepts: https://github.com/DennisOSRM/Project-OSRM/wiki/Graph-representation |
|
There is two areas in OSRM where you want to factor in elevation.
The first one needs to be handled during the preprocessing chain. And the height must be modeled as a penalty to the travel time. The rationale behind this is that uphill takes longer than downhill. This way the computed path is still a fastest one, but also considers elevation. Now, the best way to do this is to compute a penalty for each segment, when the graph is expanded, i.e. here: The second area is the computation of a height profile. It is probably best to query either an external or external data source with the computed path. For this scenario, I would query some external visualization, i.e. a web service or something similar, that takes the geometry of the route at once and returns some image or similar representation of the elevation profile. |
|
I'm still wrapping my head around all this, but i see two options: Handle elevation like turn penalty is handled in the lua_turn_penalty branch at https://github.com/DennisOSRM/Project-OSRM/blob/21c535a277cc8b53ecfbeefaebaea594d58ec139/Contractor/EdgeBasedGraphFactory.cpp#L282. It seems this is very similar to what Dennis suggested above. This would involve calling out to a lua segment_function for each segment, passing in its geometry. Lua can the use elevation data to return some weight, which OSRM uses to adjust the speed of the segment. This approach could perhaps be generalized, so that the segment_function would process both turn penalty, height penalty, and perhaps other things related to the segment. If I understand things correctly, each turn (which includes moving from one segment to the next on a straight way) is processed by OSRM. Segment processing would happen after the extraction process, in the step where the OSM data is transformed to an edge-expanded graph. The drawback of this approach might be that way processing and segment processing is separated, and you might need way info when processing the segment. (What concrete examples of this exist?) Combine way and segment processing during extraction. For each way, call out to a lua way_function like we do now, but in addition to the way, pass an array of the segments that it consists of. Lua can then do the normal way processing, but in addition, it can loop over the segments, and use elevation data to set two speed factors for each segment (forward/backback), or nothing if there's no elevation OSRM would then combine the way weight with the segment weight when building the edge-expanded graph. |
|
hello. yesterday i finished my work, which does currently:
i use the berlin.osm.pbf file for testing and this takes: ./osrm-extract: 55sec instead of 41sec i think the penalties are quite good for the extra-logic. (mainly for the elevation stuff). the files created by ./osrm-prepare are nearly the same size (590k edges instead of 560k edges). some of the edges are for the push bike logic and some are for climbing/falling. i ignore climbings/fallings for less than 1 percent, and so there are not so much extra edges. the next steps are:
some words about the segment_function callback: first i wanted to integrate the lua-fkt into the EdgeBasedGraphFactory class. but that was to complicated for me, as i didnt know the osrm internals as good. as well in this case it is necessary to change the osrm file format (at least with the speedBackward parameter). |
|
Thanks for sharing your work prozessor13. In relation to elevation, what are the differences from karmes code? |
|
the diffeneces are mainly:
pseudocode |
use the same weight for both directions (suggested by prozessor13 in issue Project-OSRM#546) comment-only for now
|
max wukits notifications@github.com writes:
the problem with that approach is that you can't upsample the line segments
started with a similar approach, nothing wrong with it. If you are after But there are some good reasons to use a library like gdal:
good reasons to use something like the elevation-profile service:
regarding performance: but in the end I don't think we should have an overly long discussion
i think there is a typo here, maybe you mean way_function instead of this is really a consequence of the point above: because you don't do upsampling you can calculate the speed in the way but looking at:
good one while taking a look at this, i noticed that my old patch did compare the
only real differences i see there:
Greetings, |
|
Project OSRM notifications@github.com writes:
nearly missed that one |
|
Just some additional comments regarding this one (nothing really new): Project OSRM notifications@github.com writes:
there is also the case where you may want to perfer a flat way even if
of course it would be nicer if the the profile would be readily |
|
hello
what do you mean with upsampling in this case?
i agree with you, that my custom implementation ist not the best one for
we do only bicycle-routing, and in this case a maxspeed-setting is not and in our case we dont calculate routing-time based on the speed
hmm. i dont understand what you mean with upsampling. but the speed of a
yes thats right, but doesnt matter in our scenario.
you are right. and thanks for your code. it was a gread basis to implement our needs :) ps: i know that my code is not generally usable, i didnt made tests and |
|
it might be better to continue the discussion on the mailinglist https://github.com/DennisOSRM/Project-OSRM/wiki/Mailing-list |
|
max wukits notifications@github.com writes:
line segments might be long (there might be a mountain or valley between => with upsampling i mean taking elevation samples between start and [...]
no problem - i only wanted to make clear where the problems are my solution now is to split the osm ways at intersections and adding karme |
|
A digital elevation model for Denmark was recently released to the public. We would like to use this datasets to avoid hills. (Yes hills are tiny in Denmark, but people are used to flat roads :-)) Free download (just need to create an account): http://download.kortforsyningen.dk/content/dhmterr%C3%A6n-16-m-grid |
|
Emil Tin notifications@github.com writes:
sounds great
some time ago was cycling from fensburg north, there were quite some [0] http://en.wikipedia.org/wiki/DFSG |
|
Free download (just need to create an account): http://download.kortforsyningen.dk/content/dhmterr%C3%A6n-16-m-grid. I'm not familiar with DFSG. You can read about the license for the data at http://download.kortforsyningen.dk/content/vilk%C3%A5r-og-betingelser (in danish). |
|
Emil Tin notifications@github.com writes:
via google translate it looks quite good i think i also found an english version at: will take a look |
|
got an account, downloaded 10m sample is there a way to directly download all the tiles without manually clicking in the web-frontend? |
|
i don't think so. it's from a time when you paid for each tile. |
|
To generate elevation profiles from an OSRM-computed route, I'm currently using Redis with Lua. My Redis store contains SRTM tiles for the UK, plus a Lua script (loaded with SCRIPT LOAD) which takes a polyline and returns an elevation profile. It's fast and easy to understand. It strikes me that this would be a very easy and flexible way to provide support for external data in OSRM: allow the user to register Redis-stored Lua scripts (which are identified with a SHA1 value) to be called at certain points in the processing with a defined interface. These scripts could then be capable of assessing elevation, traffic, pollution etc. as per Emil's original issue. |
|
Richard Fairhurst notifications@github.com writes:
did you try elevation-profile [0]?
did you test my waysplit approach? greetings, |
|
I'd rather not run a further preprocessing step if possible. I have looked at the elevation-profile code but it seemed easier for me to hack something up in Lua, rather than try and integrate a lot of code with lots of dependencies (always a problem on OS X) and in a language I don't understand. :) |
|
Richard Fairhurst notifications@github.com writes:
imho at the moment there is no other solution if you want "correct"
I see maybe I should provide preprocessed osm/pbf files?
don't be afraid of scheme (it is really simple) |
|
I've now implemented (in a quick and dirty fashion) the Redis+Lua approach. There's a fairly significant slowdown but that's fairly inevitable when interpolating from SRTM data anyway. Works fine with a single-county extract; just about to leave it to churn overnight on the UK .pbf! |
|
possible by querying postgis from lua. this example avoids landusages=industrial: |
|
Is it really real-time or the postgis query is made before preparing the routable network? |
|
postgis is queried during the OSRM data preparation. during routing postgis is not accessed. |
|
Hi,
We are interested about the second point, as we have elevation data in the source (so each vertex in the source has height information). Since it's vector data, we want to avoid calling a second Webservice, as it would involve heavy geometry comparison. So we are rather thinking about the possibilities to implement it into OSRM. Thanks for any hints and thoughts about that! |
|
Raster support has landed in |
|
@georgbachmann here's the example profile |
|
Thanks... I already found it... looks very promising! nice! |
|
For real-time communication, yes. For everything that needs to persist or could potentially be of interest to more people => tickets. There's a webchat IRC client: http://webchat.oftc.net |

What would be the most elegant way to support the use of various external data when pre-processing data?
Data types could include:
It might be possible to create a common way to handle all these cases, since it seems they all involve sampling an external data set, and translating it into modified cost/speed of the individual way segments.
The issue #271 has a discussion on elevation data.
@prozessor13
The text was updated successfully, but these errors were encountered: