Page 1 of 1

Toll Distance Calculation

Posted: Fri May 05, 2023 5:44 am
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?

Re: Toll Distance Calculation

Posted: Fri May 05, 2023 8:28 am
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

Re: Toll Distance Calculation

Posted: Fri May 05, 2023 11:02 am
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' ];
            }
         }
      }

Re: Toll Distance Calculation

Posted: Wed May 10, 2023 2:05 pm
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.

Re: Toll Distance Calculation

Posted: Fri May 12, 2023 6:59 am
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

Re: Toll Distance Calculation

Posted: Fri Jul 07, 2023 11:47 pm
by Bernd Welter
SPOILER ALERT - this feature is about to come in V2.30...