Visualize osm_ids for traffic speed edits
Total Noob here, apologies for triviality of question.
I am dealing with a challenge similar to the one posted in this closed issue https://github.com/Project-OSRM/osrm-backend/issues/1313. I want to overlay road segments with my own shapefiles that delimit the extensison of a flooding event, to then use the osrm package in R to develop isochrone maps under certain flooding scenarios.
It seems like a csv file can be used to update the speed of selected road segments that are defined by their from and to_osm_id. What would be a good way to visualize my data (New York State) in an environment that allows me to overlay road segments with my data (shapefiles)?
I would have assumes that the process would be something like:
a) access the roads layer of my OSRM server and deploy them in a GIS environment (e.g. qgis, R...) b) perform overlays and identify road segments where the speed needs to be edited to a given value (e.g. 0 if very flooded, 5 mph if flooded, no changes if not flooded) c) create a csv file with the from and to osm_id of the edited roads, and the new speed (in km/h) d) run osrm-customize with the csv as input e) run the new osrm server and connect my R script to it.
But as of now I have no idea of how to open the roads (edges?) and their nodes in a GIS environment. So I am stuck between the partition and the customize steps because I cant access the roads geometries and their node ids. Is there a way to do this? perhaps this could be done using the city-name-latest.shp file with the roads to find their ids?
Thank you!
I can't answer your question, but wanted to leave an alternative here: depending on your exact use case (e.g. directions vs performant matrix) it would probably be least-resistance to consider another routing engine. If performance is not of essence here and you simply want to be able to calculate (multi-)waypoint routes, not OD matrices with 1000s of locations, you could look into Valhalla or ORS which support avoid_polygons/locations (actually that's more exclude_polygons/locations).
The avoid_polygons approach takes quite some resources at runtime so a route request can take > 1 sec if your flooding regions extend more than a few dozen square kilometers. I can only talk for Valhalla, but ORS has to take a similar implementation approach and I suspect it to be even slower for longer routes.
Valhalla: https://github.com/valhalla/valhalla/blob/master/docs/api/turn-by-turn/api-reference.md#other-request-options
ORS: https://openrouteservice.org/dev/#/api-docs/v2/directions/{profile}/post (nested in the options parameter)
Thank you for the advice Nils!
A polygon-based road avoidance would be really optimal, but unfortunately I am using a Windows machine (always makes things harder). However, I am GIS savvy enough to come up with some kind of routine that would identify the from/to osm_ids of the affected roads.
I feel like so far my struggle has been to identify what the input osm_ids are supposed to be. I am hesitant about whether they are hidden edge nodes that I cant see, or just any osm_id, such as a point from the osm.pbf that overlaps with a road segment, like a highway=crossing point.
This page says it's OSM node IDs https://github.com/Project-OSRM/osrm-backend/wiki/Traffic Every OSM way consists of OSM nodes. So this is not an overlap, but the actual id of a point on a road.
If you are GIS savvy, I would suggest you alter or add max_speed and access tags to your local OSM extract as a preprocessing step. I think that would be easiest. You can then even open your extract (if it is small enough) in an editor or other GIS software to verify your preprocessing
Thank you Datendelphin. That (first paragraph) confirms my suspicions - but also that I have not been able to open the actual road node points in a GIS software or a programming environment like R or Python.
The pre-processing approach you suggest sounds too good to be true based on the things I have seen so far, but it would be really wonderful. When I load the extracted .osm data to QGIS, for example, it first asks me what layers I want to add (points, lines, multilines...). There is no max_speed field in the attributes tables of the line nor the multiline layers. I do see, however, mentions to the max_speed in some rows under the "other_tags" column, shown as maxspeed. For example, this is the text included under that column for a given row:
"access"=>"yes","bicycle"=>"yes","foot"=>"yes","maxspeed"=>"30 mph","motor_vehicle"=>"yes","oneway"=>"no","tiger:cfcc"=>"A41","tiger:county"=>"Albany, NY","tiger:name_base"=>"North","tiger:name_type"=>"St","tiger:reviewed"=>"no","tiger:zip_left"=>"12054"
Making changes in that row seems feasible. My process would be:
- To open the lines layer in a programming environtment, e.g. in R, as an sf. To do this, I have to first export the data as a .shp.
- Spatially select lines that overlap with flooding extensions, and alter the text under the other_tags field, changing the speed.
- To return the lines file to the .osm format (is this possible?)
My concern then is about keeping the .osm dataset integrity for the next steps (partition, route, etc). How would editing this data work? Can I edit it data in R or ArcMAP/QGIS without converting the .osm file to a .shp file? Or if I did that (opening .osm file in QGIS, export lines as .shp, edit data in a programming environment), how can I switch it back to an .osm dataset with the corrected data in the lines dataset, so that I can go on with the OSM server set-up process? or if I am missing something more basic - what is the right way to open / access / edit the maxspeed info in a programming environment / gis software?
Thank you for your help here. Super appreciated.
If pre-processing is an option for you, then you can also use lua scripting to get there. Look at this snippet by @TimMcCauley : https://gist.github.com/TimMcCauley/5bd61b968849ebca4974b636e16f4fa9#file-car-location-dependent-speeds-lua-L448-L464
Only those lines were added to the default car lua profile. It will update the maxspeed that OSRM sees for every edge within the polygon(s). Instead of a factor you'd probably assign a very low maxspeed.
That looks pretty great! I see it is feeding the polygons to the .lua through as a GeoJSON Feature Collection? so all I need to do is:
- Call this .lua, stored in my directory, instead of the car.LUA I was using
- Use a GeoJSON stored in my directory as an input for the polygons where the speed should be much lower or 0
Questions then are:
- What do you mean that only those lines were added to the default car.lua profile? the snippet you cited? wouldnt that mean than then all I need to add to the car.lua default profile is the --location-dependent-data GeoJSON file? or do you mean that the default car profile has all but those lines and hence is not updated through the input?
- Can the GeoJSON have more than one single geometry (e.g. be a conversion of a shapefile with several polygons converted to GeoJSON?)
- Can the factor be 0?
If this is beyond your knowledge, I will ask in Tim's repo. Thank you for all these hints!
Hi Nils and datendelphin - I posted a question in Tim's code. I am dropping the link here in case you have any advice. Almost there!
https://gist.github.com/TimMcCauley/5bd61b968849ebca4974b636e16f4fa9#gistcomment-3799396
This issue seems to be stale. It will be closed in 30 days if no further activity occurs.