Exact route from GPX file

I am creating route planner, I had no problems with “manual drawing” of route, but I came to a stop when I try to import GPX file. Showing route line of GPX route is not a problem, but what I try to do is create ORS route from GPX points so that I can get extra information like surface and waytype and also segments where later on I can drag route and just adjust part of route where that segment is.

But when I call directions API with GPX points, route is pretty different - due to route optimization for picked profile (avoiding construction areas, routing to different streets etc.).

What I would need is routing to exact points that I give without any avoiding or optimization. I am self hosting ORS and tried to send entire 1600 points from GPX but it’s not helping.

Is there any way to use ORS to achive what I am after or is this simply not possible ?

Hey

if I understand correctly, you want to “re-calculate” a route from a given gpx track.

The openrouteservice is in general of course able to do that - how closely the calculated route follows the gpx track depends mainly on the granularity of the points sampled from the gpx track that you use to calculate the route.

However, there are a few things I can think of that make this tricky.

  • GPX waypoints tend to bounce around a bit. The openrouteservice has to “snap” all points (of which most probably are not directly on a street) to the street network. Depending on the amount of “bounce” in your GPX waypoints, this might already introduce an error.
  • GPX tracks represent what a person actually did - whether that is advisable or even legal does not matter.
    The openrouteservice tries to follow e.g. the legal situation represented by the OpenStreetMap data as best as it can. If you, for example, walk along a path labelled with access=private, since you know no one cares, the openrouteservice will not route you along this path. Here is an example:

    All roads inside the built-up area are private (and thus greyed out), so the openrouteservice will not route there.
  • By default, an openrouteservice instance will only route up to 50 or so waypoints. You can configure this, see ors.engine.profiles.<PROFILE-NAME>.service | openrouteservice backend documentation

Feel free to share an example of a route where the GPX track and the re-calculated route differ - ideally as a screenshot, and the corresponding coordinates you sent to the openrouteservice. That always makes discussion around this way easier.

Best regards

Here is example where one part of cycling route goes off:

Same GPX file import on Strava:

After more looking into it, I guess problem is that this section is marked as bicycle = no on OSM.

This is Strava section of previous example:

Now I had one more problem on this section for example:

I would get same route in my app. I manage to fix this by code change where I allow routing if waytpe is construction and that solved it.

As for first example I should probably change code by removing checking for tags bicycle and just allow it.

Is perhaps there any, more “correct” way to handle this ?

One more example.
Strava is going straight as it should:


My app:


Reason is again probably tag bicycle = no in OSM Way: ‪Poljanska cesta‬ (‪882141353‬) | OpenStreetMap

Hey,

yeah, the “problem” here is the construction or bicycle=no tag.
However, I would heavily advise against changing the code that influences the routing.

openrouteservice is a routing engine, first and foremost.
The main feature of a routing engine is to calculate correct, reliable routes - as correct as the underlying data allows, at least.

If the openrouteservice does not calculate a route, then it does so because you should not go along this route - for example because it is a road under construction or because bicycles are not allowed on that road.
Of course ORS cannot stop you from still doing so (breaking or not breaking the laws in your country), but the openrouteservice should not tell you to do that.

Mapping GPX tracks that have been driven onto the map is mapmatching, and there are services that allow you to do just that, such as this one - as a quick google search reveals.
You can then get infos about waytype, surface, … from the OpenStreetMap directly.

Using these GPX tracks as a base for routes, in order to adjust them, is then again routing, talked about above.

If - and only if! - the underlying OSM data is incorrect, meaning that the OSM states bicycle=no even though bikes are allowed on that road, then that should be fixed in the OpenStreetMap, and not worked around in the openrouteservice code.

Best regards