Reconstructing a route from a polyline

VERSION 1.26.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 other planning services.

Reconstruction modes

Polyline reconstruction supports three distinct 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, such as 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 using this mode, the algorithm tries 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 still 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. If there are road restrictions on the input path, the algorithm attempts to find local detours. The resulting reconstructed follows the road network accurately and complies with applicable 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 route as closely as possible to the provided route polyline, while ignoring time-dependent driving and legal restrictions. This helps preserve the input polyline’s geometry. The input polyline is expected to be normalized, without loops or gaps. The resulting route follows the road network but may violate driving restrictions, resulting in an illegal route.

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, provide a list of supporting points that depict the desired route geometry, and designate the reconstruction mode to use. 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: