GraphHopper.com | Forum | GitHub | Maps | Blog

Optimization response with route geometries


#1

Route geometries for vehicle routes can now be included in the optimization response. Thus, you do not need to do extra routing to get the polyline for each route. By default, the Optimization API does not include it. You can enable this by adding

"configuration": {
   "routing": {
      "calc_points": true;
   }
}

to your json request.

For each route, you are then provided with the geometry much like this:

"routes": [
    {
      "vehicle_id": "my_vehicle",
      "distance": 1898748,
      "transport_time": 58835,
      "completion_time": 58835,
      "waiting_time": 0,    
      "points": [
            {
              "coordinates": [ [lat,lon], [lat,lon], ... ],
              "type": "LineString"
            },
            ...
       ]

Points is an array that stores a geojson for each leg in the vehicle route. Therefore, if your route has 6 activities including start and end, it has a length of 5, i.e. it includes 5 linestrings. If “coordinates” only has one entry, you get a “Point” rather than a “LineString”, i.e.:

{
   "coordinates": [lat,lon],
   "type": "Point"
}

This feature enables you to render your solution on a map without knowing the underlying vehicle routing problem :slight_smile:.

Happy routing!

BTW: This feature is beta and therefore not yet documented in our doc.


#2

This is now part of the official documentation


#3

@stefan

If I enable routing in Optimization API, routing points of optimized locations are the same result from Routing API?


#5

Yes, internally we request the Routing API in an efficient manner.