Reconstructing a route from a polyline

VERSION 1.20.0
PUBLIC PREVIEW

In addition to route planning, this method provides another approach to obtain routes from the SDK. It offers the flexibility to import routes from custom sources, such as GPX files, or routes generated by different planning services.

Reconstruction modes

Polyline reconstruction comes in three distinct reconstruction modes. If no mode is specified, the SDK defaults to track.

  • track: Use this mode when the given polyline originates from a third-party source like for example a track recording. This mode provides flexibility when the provided route polyline does not perfectly align with the road network, allowing the reconstruction of the most sensible route. The input polyline may have inconsistencies such as gaps and loops. When reconstructing the route using this mode, the algorithm will try to respect the driving conditions.
  • route: This mode is suitable when the given polyline originates from a route previously planned by the same planner on the same map. The goal is to reconstruct the given route as closely as possible to the provided route polyline while adhering to driving and legal restrictions. The input polyline is expected to be normalized (aligned with the road network present on the map), without any loops or gaps. In cases where there are road restrictions on the input path, the algorithm attempts to find a local detour to accommodate these restrictions. The resulting reconstructed route tries to accurately follow the road network and comply with driving restrictions.
  • update: Use this mode when the given polyline originates from a route previously planned by the same planner on the same map. The goal is to reconstruct the given route as closely as possible to the provided route polyline, ignoring time-dependent driving and legal restrictions in order to keep the input polyline geometry stable. The input polyline is expected to be normalized, without any loops or gaps. The resulting reconstructed route tries to accurately follow the road network and might result in an illegal route due to potential violation of driving restrictions.

These reconstruction modes offer a range of options for customizing the route reconstruction process, ensuring flexibility and accuracy based on the source of the input polyline.

The provided Kotlin code demonstrates how to reconstruct a route from a list of supporting points that adheres to the itinerary, utilizing the specified reconstruction mode to achieve the desired route representation:

1fun trackToRoute(track: List<List<GeoPoint>>): Result<RoutePlanningResponse, RoutingFailure> {
2 val waypoints = (track.dropLast(1).map { it.last() })
3 val routePlanningOptions = RoutePlanningOptions(
4 itinerary = Itinerary(
5 origin = track.first().first(),
6 destination = track.last().last(),
7 waypoints = waypoints,
8 ),
9 routeLegOptions = track.map { legPoints ->
10 RouteLegOptions(supportingPoints = legPoints)
11 },
12 reconstructionMode = ReconstructionMode.Track,
13 )
14 return routePlanner.planRoute(routePlanningOptions)
15}

In this function, we define the itinerary, supply a list of supporting points that depict the desired route geometry, and designate the reconstruction mode to be utilized. This enables the generation of routes tailored to specific track data.

Next steps

After learning about polyline reconstruction, here are recommendations for the next steps: