Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script that generates a map plot of a VROOM solution #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gabriele3vi
Copy link

Script that uses Folium to generate a map showing the stops and routes taken by the vehicles. Each vehicle is represented by a different color. Currently, there are 15 possible colors.

Copy link
Contributor

@jcoupey jcoupey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR! I especially like the ability to generate a quick map view with a single command for instant feedback.

I made a couple improvements suggestions, what do you think?

import json
import sys

# Given a VROOM solution with latlng locations, generates a map of the paths of the vehicles (up to 15 vehicles)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the 15 limit is related to the size of the colors list. It would be possible to loop through that list, pretty much as we do it in the plot.py script here.

Comment on lines +15 to +20
first_step = vroom_res['routes'][0]['steps'][0]
center_lat = first_step['location'][1]
center_lng = first_step['location'][0]

map_center = [center_lat, center_lng]
map = folium.Map(location=map_center, zoom_start=10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the problem extent, we may want a different center and zoom. For example for a country-scale problem, the solution does not fit in the initial view by default.

It would be possible to expand a bounding box while going through the routes and steps, then after that fit the map zoom to this bounding box.


coords.append((current_lat, current_lng))

folium.PolyLine(locations=coords, color=colors[i]).add_to(map)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most real setups, one wants to get the geometry of the route in output (see .routes[].geometry). Especially for a map plot, it would be better to use that instead of crow-flies lines as we do in plot.py.

I don't know if folium has support for polyline format (that is how the geometry is encoded in the response) but there is probably an easy way to decode that in python and then feed the array of coordinates to folium for the actual route geometry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants