def polygon_scan(location, N, R, offset, store_path): """ """ client = osrm.Client(host='http://134.76.24.136/osrm') # set up dataframe defects = np.zeros((N.size, R.size, offset.size, 2)) area_simple = np.zeros((N.size, R.size, offset.size, 2)) # area_weighted = np.zeros((N.size, R.size, offset.size, 2)) mean_R = np.zeros((N.size, R.size, offset.size, 2)) R_full = np.zeros((N.size, R.size, offset.size)) N_full = np.zeros((N.size, R.size, offset.size), dtype=int) offset_full = np.zeros((N.size, R.size, offset.size)) # calculation Npolygons = N.size * R.size * offset.size counter = 0 for k, n in enumerate(N): for i, r in enumerate(R): for j, alpha in enumerate(offset): B = construct_polygon(n, r, location, offset=alpha) angles, areas, meanR = measure_polygon(location, B, client, meanR=True) mean_R[k][i][j] = meanR defects[k][i][j] = 2 * np.pi - np.sum(angles, axis=0) area_simple[k][i][j] = np.sum(areas, axis=0) / 3 R_full[k][i][j] = r offset_full[k][i][j] = alpha N_full[k][i][j] = n counter += 1 print("{} of {} polygons evaluated.".format( counter, Npolygons)) # if necessary, create directory for storing if not os.path.exists(store_path): os.makedirs(store_path) # set up dataframe df = pd.DataFrame() df['defect_duration'] = (defects[:, :, :, 0]).flatten() df['area_duration'] = (area_simple[:, :, :, 0]).flatten() df['meanR_duration'] = (mean_R[:, :, :, 0]).flatten() df['defect_distance'] = (defects[:, :, :, 1]).flatten() df['area_distance'] = (area_simple[:, :, :, 1]).flatten() df['meanR_distance'] = (mean_R[:, :, :, 1]).flatten() df['radius'] = R_full.flatten() df['number of edges'] = N_full.flatten() df['offset'] = offset_full.flatten() # save data np.save(store_path + "/location.npy", location) df.to_csv(store_path + "/scan_data.csv")
def TimeOSRM(lat1, lon1, lat2, lon2): import osrm s = osrm.Client( host='http://localhost:5000') # consulta ao servidor local OSRM r = s.route(coordinates=[[lon1, lat1], [lon2, lat2]], overview=osrm.overview.full) t = ((r["routes"][0]["duration"]) / 60) return t
def DistanceOSRM(lat1, lon1, lat2, lon2): import osrm s = osrm.Client( host='http://localhost:5000') # consulta ao servidor local OSRM r = s.route(coordinates=[[lon1, lat1], [lon2, lat2]], overview=osrm.overview.full) d = ((r["routes"][0]["distance"]) / 1000) return d
def main(): print("f**k!") src_file = sys.argv[1] start_line = int(sys.argv[2]) end_line = int(sys.argv[3]) client = osrm.Client(host='http://localhost:5000') with open(src_file, 'r') as src: cnt = -1 pool = mp.Pool(8) manager = mp.Manager() p = [] while True: line = src.readline() cnt += 1 if cnt < start_line: continue if not line or cnt > end_line: break pp = pool.apply_async(map_matching, args=(cnt, line, client,)) p.append(pp) pool.close() pool.join()
def __init__( self, origin: None, destination: None, origin_name: str, destination_name: str, server_address: str, travel_mode: str, show_route: str, units: str, ) -> None: self.origin = origin self.destination = destination self.origin_name = origin_name self.destination_name = destination_name self.travel_mode = travel_mode self.show_route = show_route self.duration = None self.distance = None self.route = None self.base_time = None self.units = units self._client = osrm.Client(host=server_address, profile=travel_mode)
def __init__(self, n_threads=8): # self.urllist = [] self.n_threads = n_threads self.executor = futures.ThreadPoolExecutor(max_workers=self.n_threads) self.client = osrm.Client(host='http://localhost:5000')
def setUp(self): self.client = osrm.Client(host=OSRM_HOST, timeout=1) self.mock_session = MagicMock() self.mock_client = osrm.Client( host=OSRM_HOST, session=self.mock_session)
pocz= replace_coord(get_fac()) fini = replace_coord(get_costum()) place = geocoder.osm("Kino nowe horyzonty") print(place.latlng) coords = place.latlng print(type(coords[0])) client = osrm.Client(host='http://router.project-osrm.org', profile='car') response = client.route( coordinates=[pocz, fini]) print(get_distance(response)/1000,'km') print(response) trip = route_coords(response) m = folium.Map([51.1380, 16.7294], zoom_start=9) folium.Marker(replace_coord(pocz )).add_to(m)
counter += 1 for i, s in enumerate(tri.simplices): for j in range(3): v1 = s[j] v2 = s[(j + 1) % 3] if v1 > v2: try: idx = edges.index((v2, v1)) simplices_to_edges[i][j] = idx except: edges.append((v2, v1)) simplices_to_edges[i][j] = counter counter += 1 # measure edges client = osrm.Client(host='http://134.76.24.136/osrm') edge_lengths = np.zeros((len(edges), 2)) for i, e in enumerate(edges): A = coordinates[e[0]] B = coordinates[e[1]] edge_lengths[i] = get_tripmeasures(A, B, client) print("{} of {} edges measured.".format(i + 1, len(edges))) # assign lengths to simplices D = np.zeros((N_triangles, 3, 2)) for i in range(N_triangles): simplex = tri.simplices[i, :] for j in range(3): e = simplices_to_edges[i][j] D[i][j] = edge_lengths[e]
def osrm_init(): global client client = osrm.Client(host=current_app.config['OSRM_URL'], profile='foot')
from csvsort import csvsort import pandas as pd import csv from datetime import datetime import osmnx as ox import osrm as osrm from reportlab.pdfbase.acroform import annotationFlagValues from pymongo import MongoClient from bson.int64 import long client = osrm.Client(host='http://osrm-1644136849.us-east-1.elb.amazonaws.com') csv_file = "traffic-data-2.csv" G = ox.graph_from_bbox(12.867853, 12.842623, 77.803543, 77.775726, network_type='drive') rider_last_value = {} conn = MongoClient('localhost', 27017) collection = conn.config.geo_spatial def find_nearest_node(coordinate): geom, u, v = ox.get_nearest_edge(G, (coordinate['lat'], coordinate['lng'])) return u def calc_distance_between_nodes(nodeA, nodeB, total_time, time_entered): response = client.route( coordinates=[[G.node[nodeA]['x'], G.node[nodeA]['y']], [G.node[nodeB]['x'], G.node[nodeB]['y']]],