Exemple #1
0
 def osrm_query(self, list_points, tries=0, max_tries=5):
     try:
         client = ORS(base_url=self.base_url)
         response = client.directions(list_points, 'driving-car', format='geojson',
                                      instructions=False,)
         response_dict = {'coordinates': response.geometry,
                          'type': 'LineString'}
         route_line = shape(response_dict)
     except:
         tries += 1
         if tries > max_tries:
             route_line = self.route_from_nodes(list_points)
         else:
             route_line = self.osrm_query(list_points, tries)
     return route_line
Exemple #2
0
 def setUp(self):
     self.key = "sample_key"
     self.client = ORS(api_key=self.key)
Exemple #3
0
 def setUp(self):
     self.key = 'sample_key'
     self.client = ORS(api_key=self.key)
Exemple #4
0
import matplotlib.pyplot as plt
import matplotlib.colors as clrs
from routingpy import ORS

from shipment import Shipment
from shipment_step import Shipment_step

client = ORS(api_key=API_KEY)


def find_unopt_distance(shipment_list, repetition):
    plot_file = f'route_plots/plot_unopt_{repetition}.svg'
    fig, ax = plt.subplots()
    route_color = 'darkcyan'
    xmin = None
    ymin = None
    distances = []
    for shipment in shipment_list:
        pickup_loc = shipment.pickup.location
        dropoff_loc = shipment.delivery.location
        if xmin == None or ymin == None:
            xmin = pickup_loc[0]
            ymin = pickup_loc[1]
            xmax = xmin
            ymax = ymin
        xmin = min(xmin, pickup_loc[0], dropoff_loc[0])
        ymin = min(xmin, pickup_loc[1], pickup_loc[1])
        xmax = max(xmin, pickup_loc[0], dropoff_loc[0])
        ymax = max(xmin, pickup_loc[1], pickup_loc[1])
        lons = [dropoff_loc[0], pickup_loc[0], dropoff_loc[0]]
        lats = [dropoff_loc[1], pickup_loc[1], dropoff_loc[1]]