From API to local hosted VROOM + ORS via python SDK

Hello all you wonderful people,

I’ve been able to setup ORS (port 8080, server status: healthy) and VROOM (listening on port 3000, sent request, code = 200) correctly with no issues. Previously I was able to use the api with python + folium to generate maps and routes quite easily, but am now switching to self-hosted. Before I switched to local I utilized the following lines of code:

import requests
import folium
from folium.plugins import BeautifyIcon
import openrouteservice as ors

client = ors.Client(key='#######################')
m = folium.Map(location=[44.9778, -93.2650], tiles='cartodbpositron', zoom_start=11)

#more lines

optimized = client.optimization(
    jobs=jobs,
    vehicles=vehicles,
    geometry=True,  ## will output the geometry,
)

# Add the output to the map
for color, route in zip(['green', 'red', 'blue', 'orange'], optimized['routes']):
    decoded = ors.convert.decode_polyline(route['geometry'])  # Route geometry is encoded
    gj = folium.GeoJson(
        name='Route {}'.format(route['vehicle'] + 1),
        data={"type": "FeatureCollection", "features": [{"type": "Feature",
                                                         "geometry": decoded,
                                                         "properties": {"color": color}
                                                         }]},
        style_function=lambda x: {"color": x['properties']['color']}
    )

    gj.add_to(m)

folium.LayerControl().add_to(m)

And my inquiry is how to exactly change the lines:

optimized = client.optimization(
    jobs=jobs,
    vehicles=vehicles,
    geometry=True,  ## will output the geometry,
)

to work with the following lines of code and my local instance.

I’m currently using

call = requests.post('http://localhost:3000', json=body, headers=headers)

to post the body, inclusive of vehicles and locations, to VROOM.

Any help is appreciated, Thank you.

Hey,

this is a question about using the VROOM API directly, so please refer to VROOMs help channels for more questions about this.

The VROOM API is documented on github. I think your body should include the same jobs and vehicles as the call to the optimization method, in a json with keys jobs and vehicles. For using geometry, "options":{"g":true} should work.

Best regards

1 Like

Thank you. Up and running.

1 Like