Page 1 of 1

How to link SERVICE tour events to waypoints in xRoute response

Posted: Thu Sep 25, 2025 1:18 pm
by CAPcargo
I have a question about how to correctly determine the time and distance between waypoints in the xRoute response.

In our product, we initially used calculateRoute without breaks, relying on the RouteResponse/waypoints property to obtain the required data (time and distance between waypoints).

Since we’ve started including driver breaks from xRoute, we also use the RouteResponse/events property to get the break events.
In our product, breaks are treated as waypoints, so the BREAK tour events we convert them in waypoints.

Each event in RouteResponse/events have distanceFromStart and travelTimeFromStart. To correctly calculate the actual time and distance between waypoints (waypoints + break events), I need to determine which SERVICE tour event belongs to which waypoint.

From analyzing the response, the pattern appears to be (check attached image):
  • All events following a waypoint belong to it.
  • Except for the last waypoint, where SERVICE events are listed before the waypoint.
While this could work in practice, I’d like to ask whether there’s a more reliable or official way to link SERVICE tour events with their corresponding waypoints ?.


P.S.

1. I also enabled the nodes property and considered linking them through nodeIndex, but found out that that`s not the proper property to use.
2. In our product, each waypoint always has exactly one SERVICE event, which makes the mapping simpler.

Regards,
Marko Arsovski
CAPcargo

Re: How to link SERVICE tour events to waypoints in xRoute response

Posted: Thu Sep 25, 2025 1:55 pm
by Bernd Welter
Hi there,

if you want to determine traveltime and distance between waypoints you could look into the "legs":
com.ptvgroup.xserver.xroute.Leg
  • 7 waypoints (triangles)
  • 6 legs
  • many tour events
legs.png
legs2.png
Isn't that sufficient?

Bernd

Re: How to link SERVICE tour events to waypoints in xRoute response

Posted: Thu Sep 25, 2025 2:16 pm
by Maximilian Vogel
Hi Marko,

I have not checked everything in detail, but here are some quick comments that hopefully help a bit:

On a more unrelated note: Since xServer 2.37 xRoute will also report TOUR_EVENTs of type "DRIVING" after each non-driving TOUR_EVENT (after BREAK and SERVICE events). Keep that in mind when upgrading to that or a newer version. The event structure in your screenshot would look differently then as it should be WaypointEvent, TourEvent (Service), TourEvent (Driving), WaypointEvent, TourEvent (Service), TourEvent (Driving), ...

From analyzing the response, the pattern appears to be (check attached image):
All events following a waypoint belong to it.
Except for the last waypoint, where SERVICE events are listed before the waypoint.
That is correct and even documented like that, see "Sorting Order" in the technical concept on Route Events.
I fully understand that this looks odd. The reason, as far as I know, is because the API was designed and developed in several steps. Before the TOUR_EVENTs were introduced, it was already defined that the last event must be a WAYPOINT_EVENT. In order to not break this behaviour and applications relying on that, the TOUR_EVENTs at the last waypoint have to appear before the last WAYPOINT_EVENT.
1. I also enabled the nodes property and considered linking them through nodeIndex, but found out that that`s not the proper property to use.
That is because for non-zero service times there will be a segment of type NOT_DRIVING.

Code: Select all

    {
      "distance": 0,
      "travelTime": 1,
      "travelSpeed": 0,
      "trafficDelay": 0,
      "violated": false,
      "eventIndices": [
        2
      ],
      "type": "NOT_DRIVING"
    }
To identify events at the same location I would rather use the field "distanceFromStart" (or the coordinates). Note that if you have two identical waypoints you would have the sequence WaypointEvent, TourEvent, WaypointEvent, TourEvent all with the same value for distanceFromStart. Obviously, if this happens at the last two waypoints, this can be annoying to deal with. (It improves with xServer 2.37 and later because there would be a DRIVING event with a duration of 0 in between.) Which brings me to your question:
I’d like to ask whether there’s a more reliable or official way to link SERVICE tour events with their corresponding waypoints ?.
Unfortunately, some kind of special handling is required. Before applying your logic to evaluate the events you could patch the response and move the last WaypointEvent before the TourEvents at this waypoint. Out of my head I don't know how this influences the consistency of other pointers (for example the eventIndices in the segments list), but if you operate only on the events, this might be feasible. When moving this WaypointEvent, you should adapt the "travelTimeFromStart" by subtracting the duration of the service events.
Another way would be to look at the events from the end until the TourEvents corresponding to the last WaypointEvent are identified, so that you can handle them properly when processing the event list (from the start).

Re: How to link SERVICE tour events to waypoints in xRoute response

Posted: Fri Sep 26, 2025 8:38 am
by CAPcargo
Bernd Welter wrote: Thu Sep 25, 2025 1:55 pm Hi there,

if you want to determine traveltime and distance between waypoints you could look into the "legs":
com.ptvgroup.xserver.xroute.Leg
  • 7 waypoints (triangles)
  • 6 legs
  • many tour events
legs.pnglegs2.png

Isn't that sufficient?

Bernd
Hi Bernd,

The legs object do not contain all the details. The events node have them as Maximilian explains below.

Thank you for your response.

Regards,
Marko Arsovski
CAPcargo

Re: How to link SERVICE tour events to waypoints in xRoute response

Posted: Fri Sep 26, 2025 8:42 am
by CAPcargo
Maximilian Vogel wrote: Thu Sep 25, 2025 2:16 pm Hi Marko,

I have not checked everything in detail, but here are some quick comments that hopefully help a bit:

On a more unrelated note: Since xServer 2.37 xRoute will also report TOUR_EVENTs of type "DRIVING" after each non-driving TOUR_EVENT (after BREAK and SERVICE events). Keep that in mind when upgrading to that or a newer version. The event structure in your screenshot would look differently then as it should be WaypointEvent, TourEvent (Service), TourEvent (Driving), WaypointEvent, TourEvent (Service), TourEvent (Driving), ...

From analyzing the response, the pattern appears to be (check attached image):
All events following a waypoint belong to it.
Except for the last waypoint, where SERVICE events are listed before the waypoint.
That is correct and even documented like that, see "Sorting Order" in the technical concept on Route Events.
I fully understand that this looks odd. The reason, as far as I know, is because the API was designed and developed in several steps. Before the TOUR_EVENTs were introduced, it was already defined that the last event must be a WAYPOINT_EVENT. In order to not break this behaviour and applications relying on that, the TOUR_EVENTs at the last waypoint have to appear before the last WAYPOINT_EVENT.
1. I also enabled the nodes property and considered linking them through nodeIndex, but found out that that`s not the proper property to use.
That is because for non-zero service times there will be a segment of type NOT_DRIVING.

Code: Select all

    {
      "distance": 0,
      "travelTime": 1,
      "travelSpeed": 0,
      "trafficDelay": 0,
      "violated": false,
      "eventIndices": [
        2
      ],
      "type": "NOT_DRIVING"
    }
To identify events at the same location I would rather use the field "distanceFromStart" (or the coordinates). Note that if you have two identical waypoints you would have the sequence WaypointEvent, TourEvent, WaypointEvent, TourEvent all with the same value for distanceFromStart. Obviously, if this happens at the last two waypoints, this can be annoying to deal with. (It improves with xServer 2.37 and later because there would be a DRIVING event with a duration of 0 in between.) Which brings me to your question:
I’d like to ask whether there’s a more reliable or official way to link SERVICE tour events with their corresponding waypoints ?.
Unfortunately, some kind of special handling is required. Before applying your logic to evaluate the events you could patch the response and move the last WaypointEvent before the TourEvents at this waypoint. Out of my head I don't know how this influences the consistency of other pointers (for example the eventIndices in the segments list), but if you operate only on the events, this might be feasible. When moving this WaypointEvent, you should adapt the "travelTimeFromStart" by subtracting the duration of the service events.
Another way would be to look at the events from the end until the TourEvents corresponding to the last WaypointEvent are identified, so that you can handle them properly when processing the event list (from the start).
Hi Maximilian,

Thank you for the detailed explanation.

I see — in this case I’ll have to link the events with their waypoints on my side. We’ll test the approach across different scenarios to see how robust it turns out in practice.

We’re currently on xServer 2.34, so I also appreciate the heads-up regarding the changed behavior in later versions.

Best regards,
Marko Arsovski
CAPcargo

Re: How to link SERVICE tour events to waypoints in xRoute response

Posted: Wed Oct 01, 2025 12:23 pm
by Maximilian Vogel
We’re currently on xServer 2.34, so I also appreciate the heads-up regarding the changed behavior in later versions.
Not only are TourEvents of type DRIVING returned since 2.37, but there are also a few more improvements and bugfixes concerning TourEvents. Also, in the recently released xServer 2.38 more bugfixes and improvements related to "tour calculation" in xRoute were done. So, I recommend an upgrade. Though I don't know how relevant they are for your use case. Refer to the release notes if you're interested:
https://xserver2-test.cloud.ptvgroup.co ... th=_____11

One more detail from the technical concept on Drivers Working Hours (section "Response and Violation") I want to highlight:
A tour event is split up into multiple consecutive tour events if the tour event types or the violation types change during this period.
If I'm not mistaken, SERVICE events as well as DRIVING events can be split under certain conditions.