Toll Distance Calculation

This forum deals with any kind of routing computation whether it is simple A:B-routing, calculation of isochrones, simple matrix computation or nearest search.
Post Reply
User avatar
YellowFoxNP
Posts: 11
Joined: Wed Dec 05, 2018 6:36 am

Toll Distance Calculation

Post by YellowFoxNP »

Hi there,

i have a problem to calculate the toll distance per country. I get toll events in france from type "PASS" in the xserver response. These events don't have a relatedEventIndex or a "EXIT" event. So i don't have the chance to calculate the distance.
Here is my code snippet in PHP from which i use:

Code: Select all

if ( $event[ '$type' ] === 'TollEvent' )
{
	if ( $event[ 'accessType' ] === 'ENTER' )
	{
		$tollDistance = $response[ 'events' ][ $event[ 'relatedEventIndex' ] ][ 'distanceFromStart' ] - $event[ 'distanceFromStart' ];
		if ( isset( $tollDistancesByCountry[ $currentCountry ] ) )
		{
			$tollDistancesByCountry[ $currentCountry ][ 'tollDistance' ] += $tollDistance;
		}
		$totalTollDistance += $tollDistance;
	}
}
With this snippet i get 88.6km toll distance in france. But in real it must be around 152km. Can anybody help me to get a functional calculation based on the attached response?
Attachments
response.js
(3.68 MiB) Downloaded 226 times
request.js
(1.97 KiB) Downloaded 250 times
Maximilian Vogel
Posts: 16
Joined: Fri Dec 29, 2017 9:00 am

Re: Toll Distance Calculation

Post by Maximilian Vogel »

The missing distance is for the section "FONTAINE-LARIVIERE" and the opposite direction, right? The distance for this section by the provider (not in our data, but from https://voyage.aprr.fr/sites/default/fi ... r_2023.pdf) is 33.2 km.

The workaround that you can do is to sum up the distances of all consecutive segments that have the flag toll=true before and after the PASS event which should be all segments that are rendered as toll road in the following screenshot. If you do that you should get at least about 44 km more of toll distance as indicated by the second screenshot. That's the best you can do at the moment.
However, if you implement that you should also consider special cases like two consecutive PASS events where all segments in between have the toll flag (I found such situations for example in Florida).
fontaine_lariviere_section.png
fontaine_lariviere_route.png
Maximilian Vogel
Developer
PTV Logistics
User avatar
YellowFoxNP
Posts: 11
Joined: Wed Dec 05, 2018 6:36 am

Re: Toll Distance Calculation

Post by YellowFoxNP »

Thank you,

i changed my code to get the distance via segments and it works fine for me.

Code: Select all

foreach( $segments AS $segment )
      {
         if( isset( $segment[ 'attributes' ][ 'roadAttributes' ][ 'toll' ]
            , $segment[ 'attributes' ][ 'descriptors' ][ 'country' ] ) )
         {
            $country = $segment[ 'attributes' ][ 'descriptors' ][ 'country' ];

            if( $segment[ 'attributes' ][ 'roadAttributes' ][ 'toll' ] === true )
            {
               $tollDistancesByCountry[ $country ][ 'tollDistance' ] += $segment[ 'distance' ];
               $totalTollDistance += $segment[ 'distance' ];
            }
         }
      }
Maximilian Vogel
Posts: 16
Joined: Fri Dec 29, 2017 9:00 am

Re: Toll Distance Calculation

Post by Maximilian Vogel »

The toll flag at the segments is not vehicle dependent. So it is not necessarily correct to always sum up the distances of all segments where the toll flag is set. For example it is possible that you have to pay toll for a truck but not for a car. Then the toll distance for the car would be too high.
Maximilian Vogel
Developer
PTV Logistics
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Toll Distance Calculation

Post by Bernd Welter »

Hi Max,

sounds like it would be a good idea to add proper output KPIs in a future API version ;-)
Thanks for the hint!

Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Toll Distance Calculation

Post by Bernd Welter »

SPOILER ALERT - this feature is about to come in V2.30...
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Post Reply