How to get the road type of each road segment travelled after map-matching

hey everyone,

My “big goal” is to figure how far cyclists are willing to go to use cycling paths instead of roads.

My plan is as follow. It lacks nuance, but it’s a first step and I just want to learn how to use graphhopper.

1- take bike gps data, map-match it using graphhopper and get the length of the trip and how much of it was spent on cycling paths vs roads
2- take the same bike gps data, get directions from the first point to the last point and get the length of the shortest trip.

If “2” is 10 kilometers of roads and “1” is 5 kilometers of roads and 10 kilometers of cycling paths, then the cyclist was willing to ride 10 kilometers of cycling paths to save 5 kilometers of road.


What I have done so far:

I am not sure how to do the next step, namely converting the map-matched GPX to a list of road segments travelled.

Is this feature offered by graphhopper map-matching?

edit: this was discussed here, I dont see a solution though : Include timestamps and OSM ids when generating .res.gpx

I tried a workaround: sending the map-matched point to the routing engine and using the road class and distance returned by the routing engine.

The problem is that the route tends to do some funky detours from points to points.

My workaround in action is in this blog post (https://www.simoncoulombe.com/2020/04/map-matching-bike/) in the section ( … but we also need the actual distance travelled by road class !)

Thanks a lot for taking the time to write down a blog post with so many details.

As you encountered a problem that you can only use car and bike and not bike alone, please create an issue so that we can track the problem down. Maybe it is just some documentation missing.

Here’s something that kinda sucks : the map matching program returns a bunch of points, but it doesnt tell us the road class that was actually travelled.

This should be possible via path details, e.g. details=road_class graphhopper/docs/web/api-doc.md at master · graphhopper/graphhopper · GitHub (maybe this is not yet available for map matching, but should not hard to add)

thanks !

Where do I pass the details=road_class to the map matcher?

edit: oh wait a minute, there’s a web app for map matching… let me look at that!

java -jar ~/git/map-matching/matching-web/target/graphhopper-map-matching-web-1.0-SNAPSHOT.jar match -h
usage: java -jar graphhopper-map-matching-web-1.0-SNAPSHOT.jar
match [–instructions INSTRUCTIONS] [–max_visited_nodes MAX_VISITED_NODES] [–gps_accuracy GPS_ACCURACY]
[–transition_probability_beta TRANSITION_PROBABILITY_BETA] [–vehicle VEHICLE] [-h] gpx [gpx …]

map-match one or more gpx files

positional arguments:
gpx GPX file

named arguments:
–instructions INSTRUCTIONS
Locale for instructions (default: )
–max_visited_nodes MAX_VISITED_NODES
(default: 1000)
–gps_accuracy GPS_ACCURACY
(default: 40)
–transition_probability_beta TRANSITION_PROBABILITY_BETA
(default: 2.0)
–vehicle VEHICLE (default: )
-h, --help show this help message and exit

hey it’s working!! thanks!!

curl -XPOST -H “Content-Type: application/gpx+xml” -d @/home/simon/id_56.gpx “localhost:8998/match?vehicle=bike&type=json&details=road_class”
{“hints”:{},“info”:{“copyrights”:[“GraphHopper”,“OpenStreetMap contributors”],“took”:192},“paths”:[{“distance”:5263.839,“weight”:9.223372036854775E12,“time”:1088719,“transfers”:0,“points_encoded”:true,“bbox”:[-73.604989,45.496959,-73.555539,45.519064],“points”:“cmytGd~fMdGqQV_CrA{DhDcJt@wAKwGNiE@qGFOFy@AMP{B?c@Ew@aAqEIy@Ai@D]Nw@t@eCJOBW?[Ce@a@gCo@wCA[DWhE}LxAwDBMtJeXtIaVB]vBwFzKuZlDaJzLq\fAmCe@g@GDGAII?Qa@_@vEyLbBfA|BsGJO|A{D`CoGf@{Av@oBlBiFbEhDZoApDpCJZbEnEdEgOAA”,“instructions”:[{“distance”:579.867,“heading”:122.38,“sign”:0,“interval”:[0,4],“text”:“Continue onto Avenue Bloomfield”,“time”:115968,“street_name”:“Avenue Bloomfield”},{“annotation_text”:“get off the bike”,“distance”:45.64,“sign”:0,“annotation_importance”:1,“interval”:[4,5],“text”:“Continue onto Avenue Bloomfield”,“time”:41075,“street_name”:“Avenue Bloomfield”},{“distance”:1507.352,“sign”:-1,“interval”:[5,32],“text”:“Turn slight left onto Chemin de la Côte-Sainte-Catherine”,“time”:301454,“street_name”:“Chemin de la Côte-Sainte-Catherine”},{“distance”:1568.849,“sign”:-7,“interval”:[32,39],“text”:“Keep left onto Avenue du Parc”,“time”:313745,“street_name”:“Avenue du Parc”},{“distance”:26.362,“sign”:-2,“interval”:[39,40],“text”:“Turn left”,“time”:6778,“street_name”:""},{“distance”:22.731,“sign”:-2,“interval”:[40,44],“text”:“Turn left”,“time”:5844,“street_name”:""},{“distance”:22.337,“sign”:-2,“interval”:[44,45],“text”:“Turn left”,“time”:5743,“street_name”:""},{“distance”:209.678,“sign”:2,“interval”:[45,46],“text”:“Turn right onto Rue Anderson”,“time”:41933,“street_name”:“Rue Anderson”},{“distance”:61.903,“sign”:2,“interval”:[46,47],“text”:“Turn right onto Avenue Viger Ouest”,“time”:12379,“street_name”:“Avenue Viger Ouest”},{“distance”:128.16,“sign”:-2,“interval”:[47,48],“text”:“Turn left onto Rue De Bleury”,“time”:25630,“street_name”:“Rue De Bleury”},{“distance”:433.287,“sign”:1,“interval”:[48,54],“text”:“Turn slight right onto Rue Saint-Pierre”,“time”:86649,“street_name”:“Rue Saint-Pierre”},{“distance”:128.127,“sign”:2,“interval”:[54,55],“text”:“Turn right onto Place d’Youville”,“time”:25622,“street_name”:“Place d’Youville”},{“distance”:35.002,“sign”:-2,“interval”:[55,56],“text”:“Turn left onto Rue McGill”,“time”:7000,“street_name”:“Rue McGill”},{“distance”:262.262,“sign”:2,“interval”:[56,59],“text”:“Turn right onto Rue William”,“time”:52448,“street_name”:“Rue William”},{“distance”:231.108,“sign”:-2,“interval”:[59,60],“text”:“Turn left onto Rue Prince”,“time”:46217,“street_name”:“Rue Prince”},{“distance”:1.175,“sign”:-3,“interval”:[60,61],“text”:“Turn sharp left onto Rue Wellington”,“time”:234,“street_name”:“Rue Wellington”},{“distance”:0.0,“sign”:4,“last_heading”:6.801009028202872,“interval”:[61,61],“text”:“Arrive at destination”,“time”:0,“street_name”:""}],“legs”:[],“details”:{“road_class”:[[0,4,“residential”],[4,5,“footway”],[5,39,“secondary”],[39,45,“service”],[45,46,“residential”],[46,48,“secondary”],[48,54,“unclassified”],[54,55,“residential”],[55,56,“tertiary”],[56,60,“residential”],[60,61,“tertiary”]]},“ascend”:0.0,“descend”:0.0,“snapped_waypoints”:""}],“map_matching”:{“original_distance”:5375.200471147926,“distance”:5263.839296754671,“time”:1088719}}(base)

1 Like