Closed unbrother closed 2 years ago
Hi @unbrother, thanks for reporting.
Querying tolls (for individual triplegs) and aggregate them on route level is somewhat complicated. Depending on the country, the toll system is different. For example, in Switzerland you pay an amount once a year for the use of highways (vignette, flat rate). In contrast, tolls for routes in countries with toll stations are clearly defined and recurring. If a route from Switzerland to Italy (a system with toll stations) is queried, the costs for the route cannot simply be added up, since the return would be cheaper due to the already bought vignette in Switzerland:
library(hereR)
zh <- geocode("Zurich, Switzerland")
ge <- geocode("Genova, Italy")
rt <- route(zh, ge, transport_mode = "car", url_only = TRUE)
#> https://router.hereapi.com/v8/routes?apiKey=<YOUR-KEY>&origin=47.377,8.53977&destination=44.41048,8.93917&departureTime=2022-06-27T13:08:52%2B02:00&transportMode=car&alternatives=0&return=tolls
And the response from the HERE Routing API with &return=tolls
:
{
"routes":[
{
"id":"29dbb34e-2de7-4e32-8ad3-ec634214caeb",
"sections":[
{
"id":"bf70b11d-f423-459b-a9f5-ae35f59f2be1",
"type":"vehicle",
"departure":{
"time":"2022-06-27T13:08:52+02:00",
"place":{
"type":"place",
"location":{
"lat":47.3770155,
"lng":8.539779
},
"originalLocation":{
"lat":47.3769999,
"lng":8.5397699
}
}
},
"arrival":{
"time":"2022-06-27T18:06:17+02:00",
"place":{
"type":"place",
"location":{
"lat":44.41048,
"lng":8.9391699
},
"originalLocation":{
"lat":44.41048,
"lng":8.93917
}
}
},
"transport":{
"mode":"car"
},
"tolls":[
{
"countryCode":"CHE",
"tollSystemRef":0,
"tollSystem":"VIGNETTE SWITZERLAND",
"fares":[
{
"id":"daf1bde6-e0ad-4da6-8392-1cb974bf1a72",
"name":"VIGNETTE SWITZERLAND",
"price":{
"type":"value",
"currency":"CHF",
"value":39.0
},
"reason":"toll",
"paymentMethods":[
"passSubscription"
],
"pass":{
"returnJourney":false,
"validityPeriod":{
"period":"extendedAnnual"
}
}
}
]
},
{
"countryCode":"ITA",
"tollSystemRef":1,
"tollSystem":"AUTOSTRADE PER L'ITALIA S.P.A.",
"fares":[
{
"id":"a75e3e4f-d0d8-4ef4-8b19-a307bbf37719",
"name":"AUTOSTRADE PER L'ITALIA S.P.A.",
"price":{
"type":"value",
"currency":"EUR",
"value":2.3
},
"reason":"toll",
"paymentMethods":[
"cash",
"bankCard",
"creditCard",
"transponder",
"travelCard"
]
}
],
"tollCollectionLocations":[
{
"name":"Grandate",
"location":{
"lat":45.77395,
"lng":9.04929
}
}
]
},
{
"countryCode":"ITA",
"tollSystemRef":1,
"tollSystem":"AUTOSTRADE PER L'ITALIA S.P.A.",
"fares":[
{
"id":"5024f9f3-6c50-4a28-aeb9-1109a542447d",
"name":"AUTOSTRADE PER L'ITALIA S.P.A.",
"price":{
"type":"value",
"currency":"EUR",
"value":3.3
},
"reason":"toll",
"paymentMethods":[
"cash",
"bankCard",
"creditCard",
"transponder",
"travelCard"
]
}
],
"tollCollectionLocations":[
{
"name":"Rho",
"location":{
"lat":45.54107,
"lng":9.05848
}
}
]
},
{
"countryCode":"ITA",
"tollSystemRef":1,
"tollSystem":"AUTOSTRADE PER L'ITALIA S.P.A.",
"fares":[
{
"id":"e0e74421-5212-4140-a172-228431f161cf",
"name":"AUTOSTRADE PER L'ITALIA S.P.A.",
"price":{
"type":"value",
"currency":"EUR",
"value":11.2
},
"reason":"toll",
"paymentMethods":[
"cash",
"bankCard",
"creditCard",
"transponder",
"travelCard"
]
}
],
"tollCollectionLocations":[
{
"name":"Assago",
"location":{
"lat":45.38928,
"lng":9.13855
}
},
{
"name":"Genova",
"location":{
"lat":44.43124,
"lng":8.94574
}
}
]
}
],
"tollSystems":[
{
"id":509,
"name":"VIGNETTE SWITZERLAND",
"languageCode":"ENG"
},
{
"id":5048,
"name":"AUTOSTRADE PER L'ITALIA S.P.A.",
"languageCode":"ENG"
}
]
}
]
}
]
}
As soon as I have some more time, I will work on a proposal to integrate tolls in route queries via the the hereR package.
Request tolls for routes with transport mode "car"
, "truck"
"taxi"
or "bus"
is now possible:
vignettes
defines if vignettes should be in inlcuded in the total toll cost of routes.set_currency("<CODE>")
and a currency code compliant to ISO 4217. If the currency is not set using this function call, the currency defined in the monetary representations in the current locale is used. If the monetary formatting category "LC_MONETARY"
of the C locale is not set, "USD"
is set as default.Setup, create international route from CH to IT:
library(hereR)
set_verbose(TRUE)
zh <- geocode("Zurich, Switzerland")
#> Sending 1 request(s) with 5 RPS to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 1 response(s) with total size: 872 bytes
ge <- geocode("Genova, Italy")
#> Sending 1 request(s) with 5 RPS to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 1 response(s) with total size: 888 bytes
Request route with tolls in the currency of the system locale, including vignettes:
Sys.localeconv()[["int_curr_symbol"]]
#> [1] "USD "
(rt <- route(zh, ge, transport_mode = "car"))
#> Sending 1 request(s) with 10 RPS to: 'https://router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 64.1 Kb
#> Simple feature collection with 1 feature and 12 fields
#> Geometry type: LINESTRING
#> Dimension: XYZ
#> Bounding box: xmin: 8.42371 ymin: 44.41048 xmax: 9.13999 ymax: 47.37781
#> z_range: zmin: 68 zmax: 1225
#> Geodetic CRS: WGS 84
#> id rank section departure arrival type mode distance
#> 1 1 1 1 2022-06-30 21:45:12 2022-07-01 02:31:10 vehicle car 419278
#> duration duration_base consumption tolls geometry
#> 1 17158 16522 153.6208 58.55 LINESTRING Z (8.539779 47.3...
Request route without vignettes:
(rt <- route(zh, ge, transport_mode = "car", vignettes = FALSE))
#> Sending 1 request(s) with 10 RPS to: 'https://router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 63.7 Kb
#> Simple feature collection with 1 feature and 12 fields
#> Geometry type: LINESTRING
#> Dimension: XYZ
#> Bounding box: xmin: 8.42371 ymin: 44.41048 xmax: 9.13999 ymax: 47.37781
#> z_range: zmin: 68 zmax: 1225
#> Geodetic CRS: WGS 84
#> id rank section departure arrival type mode distance
#> 1 1 1 1 2022-06-30 21:45:13 2022-07-01 02:31:11 vehicle car 419278
#> duration duration_base consumption tolls geometry
#> 1 17158 16522 153.6208 17.77 LINESTRING Z (8.539779 47.3...
Change system locale (EUR):
Sys.setlocale("LC_ALL", "it_IT.utf8")
#> [1] ""
Sys.localeconv()[["int_curr_symbol"]]
#> [1] "EUR "
(rt <- route(zh, ge, transport_mode = "car"))
#> Sending 1 request(s) with 10 RPS to: 'https://router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 64.1 Kb
#> Simple feature collection with 1 feature and 12 fields
#> Geometry type: LINESTRING
#> Dimension: XYZ
#> Bounding box: xmin: 8.42371 ymin: 44.41048 xmax: 9.13999 ymax: 47.37781
#> z_range: zmin: 68 zmax: 1225
#> Geodetic CRS: WGS 84
#> id rank section departure arrival type mode distance
#> 1 1 1 1 2022-06-30 21:45:13 2022-07-01 02:31:11 vehicle car 419278
#> duration duration_base consumption tolls geometry
#> 1 17158 16522 153.6208 57.79 LINESTRING Z (8.539779 47.3...
Set currency to mexican peso using set_currency()
and therefore take precedence over the system locale:
set_currency("MXN")
(rt <- route(zh, ge, transport_mode = "car"))
#> Sending 1 request(s) with 10 RPS to: 'https://router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 64.1 Kb
#> Simple feature collection with 1 feature and 12 fields
#> Geometry type: LINESTRING
#> Dimension: XYZ
#> Bounding box: xmin: 8.42371 ymin: 44.41048 xmax: 9.13999 ymax: 47.37781
#> z_range: zmin: 68 zmax: 1225
#> Geodetic CRS: WGS 84
#> id rank section departure arrival type mode distance
#> 1 1 1 1 2022-06-30 21:45:14 2022-07-01 02:31:12 vehicle car 419278
#> duration duration_base consumption tolls geometry
#> 1 17158 16522 153.6208 1166.28 LINESTRING Z (8.539779 47.3...
Check transport mode without tolls:
(rt <- route(zh, ge, transport_mode = "bicycle"))
#> Sending 1 request(s) with 10 RPS to: 'https://router.hereapi.com/v8/routes?...'
#> Received 1 response(s) with total size: 111.8 Kb
#> Simple feature collection with 17 features and 12 fields
#> Geometry type: LINESTRING
#> Dimension: XYZ
#> Bounding box: xmin: 8.53388 ymin: 44.4099 xmax: 9.79494 ymax: 47.37702
#> z_range: zmin: 50 zmax: 2337
#> Geodetic CRS: WGS 84
#> First 10 features:
#> id rank section departure arrival type
#> 1 1 1 1 2022-06-30 21:45:15 2022-07-01 02:02:38 vehicle
#> 2 1 1 2 2022-07-01 02:02:38 2022-07-01 02:07:50 pedestrian
#> 3 1 1 3 2022-07-01 02:07:50 2022-07-01 02:09:05 vehicle
#> 4 1 1 4 2022-07-01 02:09:05 2022-07-01 02:14:49 pedestrian
#> 5 1 1 5 2022-07-01 02:14:49 2022-07-01 06:34:07 vehicle
#> 6 1 1 6 2022-07-01 06:34:07 2022-07-01 06:39:54 pedestrian
#> 7 1 1 7 2022-07-01 06:39:54 2022-07-01 06:41:40 vehicle
#> 8 1 1 8 2022-07-01 06:41:40 2022-07-01 06:53:45 pedestrian
#> 9 1 1 9 2022-07-01 06:53:45 2022-07-01 10:21:44 vehicle
#> 10 1 1 10 2022-07-01 10:21:44 2022-07-01 10:36:40 pedestrian
#> mode distance duration duration_base consumption tolls
#> 1 bicycle 61752 15443 15443 44.0300 0
#> 2 pedestrian 286 312 312 NA 0
#> 3 bicycle 182 75 75 0.1964 0
#> 4 pedestrian 322 344 344 NA 0
#> 5 bicycle 61856 15558 15558 44.9633 0
#> 6 pedestrian 327 347 347 NA 0
#> 7 bicycle 90 106 106 0.3447 0
#> 8 pedestrian 698 725 725 NA 0
#> 9 bicycle 30092 12479 12479 36.2990 0
#> 10 pedestrian 870 896 896 NA 0
#> geometry
#> 1 LINESTRING Z (8.539779 47.3...
#> 2 LINESTRING Z (9.0756 47.099...
#> 3 LINESTRING Z (9.07493 47.10...
#> 4 LINESTRING Z (9.07553 47.10...
#> 5 LINESTRING Z (9.0782 47.105...
#> 6 LINESTRING Z (9.52979 46.84...
#> 7 LINESTRING Z (9.5326 46.845...
#> 8 LINESTRING Z (9.5329 46.844...
#> 9 LINESTRING Z (9.53886 46.84...
#> 10 LINESTRING Z (9.58527 46.63...
Can you check with the development version of the package remotes::install_github("munterfi/hereR@feature/route-tolls")
?
I see that it is possible to request tolls for routes in the API but it would be great to be able to do it with hereR.