# Cross Border tollways calculation

Hi everyone, I was trying to calculate the tollways for driving-hgv but had some trouble.
Tollway seems to work really well in the directions api for driving-car if you stay in a single country without border crossings. It also works well for driving-car if you cross borders and have tollways in different countries. You just have to look for the border crossing in the countryinfo.

As long as I stay in a single country, it also works for driving-hgv.
However, I have a problem for trucks when I have a border crossing as the tollway values do not align with the border crossing. E.g. the country Info tells me that from waypoints 0-2490 I am in country 11, and from 2490-3670 I am in country 74. However the tollway =0 from waypoint 2384-3385, so there was a border crossing but i dont know how that relates to the tollway. In driving-car there is a waypoint for tollway that aligns with the countryinfo for the border.
In the end i get the total distance with tollway.
However there is no way for me to calculate what distance I drove with tollway in country 74 and which one in country 11.

Hey,

if I understand correctly, you request tollways and countryinfo extra-information for both the car and hgv profile on the same route.

Now where the car profile returns a waypoint in the tollway information on the border change, the hgv profile doesn’t, and it is unclear why since it should.

Could you post two minimum viable requests that exhibit this problem?

Best regards

Hi, thanks for the quick reply.
Is a python code ok?

For the driving-hgv:

import requests

body = {"coordinates":[[16.355937,48.228412],[11.490482,48.141658]],"extra_info":["tollways","countryinfo"]}

'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
'Authorization': 'API key',
'Content-Type': 'application/json; charset=utf-8'
}

print(call.status_code, call.reason)
print(call.text)

for the driving-car:

import requests

body = {"coordinates":[[16.355937,48.228412],[11.490482,48.141658]]}

'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
'Authorization': 'API-Key',
'Content-Type': 'application/json; charset=utf-8'
}

print(call.status_code, call.reason)
print(call.text)

Hey,

first, it’s important to notice that car and hgv are going different routes, so you cannot compare their responses

For hgv, I get the following extras:

{
"countryinfo": {
"values": [
[ 0, 2490, 11 ],
[ 2490, 3670, 74 ]
],
"summary": [
{ "value": 11.0, "distance": 304065.7, "amount": 68.67 },
{ "value": 74.0, "distance": 138754.8, "amount": 31.33 }
]
},
"tollways": {
"values": [
[ 0, 234, 0 ],
[ 234, 2384, 1 ],
[ 2384, 3385, 0 ],
[ 3385, 3476, 1 ],
[ 3476, 3670, 0 ]
],
"summary": [
{ "value": 1.0, "distance": 290518.1, "amount": 65.61 },
{ "value": 0.0, "distance": 152302.4, "amount": 34.39 }
]
}
}

This indicates, that at waypoint 2490 the route changes from country 11 to country 74.
The waypoints are the same for the tollways, so to find out whether you are on a tollway or not, you have to find the tollway-info that starts before and ends after that waypoint.

In this case, you’re not on a tollway (0) from waypoint 2384 to waypoint 3385.
That means, from waypoint 2384 to waypoint 2490 you’re not on a tollway in country 11 and from 2490 to 3385 you’re not on a tollway in country 74.

Any analysis regarding distances will have to be done manually, the summaries won’t calculate the “combinations” of these values.

The geometry’s waypoints do correspond to the numbers given above, so calculating the length from waypoint 2384 to waypoint 2490 will give you the distance of this no-tollway section in country 11 and the length from waypoint 2490 to waypoint 3385 will yield the same for country 74.

Best regards

Thanks for the reply, how do I calculate the length from waypoint 2384 to waypoint 2490

That depends on the technology you’re using and is a GIS rather than an openrouteservice question.

Some search regarding linestring length calculation, possibly mentioning GeoJSON and the technology of your choice, should yield decent results.

Best regards

Ok, but the tollways total distance is calculated in the output in the summary. So this is likely calculated for each segment, but just not passed via the API. So if [234,2384,1] would also pass the distance calculation, that would then make it very easy to asign each tollway to a country.

Hey,

if that is a feature that you would like to see in the openrouteservice, feel free to open a new feature request issue here.

Please make sure to check that that is not by chance a feature that has already been requested

Best regards

Here is an example from Asfinag.
In this scenario, about half of the toll is in Austria, and half of it is in germany.

However, when i do it with geojson api, it does not recognise any toll for germany

import requests

body = {"coordinates":[[16.355937,48.228412],[6.71460613328035,51.36129001869803]],"extra_info":["tollways","countryinfo"]}

'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
'Authorization': '5b3ce3597851110001cf6248b350f69eb8524d5d9aa3f8441bd9eecc',
'Content-Type': 'application/json; charset=utf-8'
}

print(call.status_code, call.reason)
print(call.text)
"extras":
{"countryinfo":
{"values":[[0,2236,11],[2236,7449,74]],
"summary":[
{"value":74,"distance":692242.1,"amount":72.74},{"value":11,"distance":259422.4,"amount":27.26}]},
"tollways":{"values":[[0,234,0],[234,2230,1],[2230,7449,0]],
"summary":[
{"value":0,"distance":704889.4,"amount":74.07},{"value":1,"distance":246775.1,"amount":25.93}]}}

That would then probably be due to how the ways are mapped in the OSM.
Do you have an example of a tollway that isn’t recognized as such?

Best regards

Yes, in this example, no tollways are recognised in germany (74)

Hey,

regarding tollways, the openrouteservice should take any toll=*-tags in the OSM into account.

According to taginfo there are over 30k toll-keys in Germany.

Could you point to a specific tollway (ideally an OSM ID) that is marked as such, but when routing is not reported as a tollway?
You can use either the context menu (right click) → Query Features when zoomed in enough or use the Map Data overlay, accessible via the Layers-Menu on the right side on osm.org.

Also note, that the toll situation, especially in germany, is a bit tricky: DE:Key:toll - OpenStreetMap Wiki

Best regards

Hey, Thanks for your reply. I think I get the problem, the ORS works well, however, the OSM data is not tagged properly.
Here is the complete list of tollways as excel for germany. https://www.balm.bund.de/DE/Themen/Lkw-Maut/Mauttabelle/mauttabelle_node.html

If we look at the first route with “Abschnitts-ID” = 2

2	Duisburg-Nord, Kreuz	Duisburg-Neumühl	1.8	A42	NW	51.48330	6.77070	51.48470	6.79410

In OSM I would get part of this route to be the OSM-ID

Weg: A 42 (290826732)
Version #7

But it has not tollway tag. So this seems to be the case for most routes. So it is a OSM issue correct?

Hey,

yes, exactly.
This has the additional “problem”, that there are quite a few different ways belonging to just this short segment - compare the corresponding relation with its 511 members^^

Best regards

Ok, so might be easier to just make a waycategory and waytype call and assume that all highways have a waytoll. I wonder why the data is so accurate in austria and almost not existent in germany.

Hey,

because Germany historically didn’t have any toll, and recent history has been… difficult
I’m not sure about the actual situation atm…

Best regards