def nodes_data(file_name, stop_points, material_weights, file_osm, geotiff): G = ox.load_graphml(file_name) lats = [a_tuple[0] for a_tuple in stop_points] lons = [a_tuple[1] for a_tuple in stop_points] nodes_coordinates = {} nodes_mass_increment = {} [nodes_coordinates.update([(list(G.neighbors(n))[0], (d['y'], d['x']))]) \ for n, d in G.nodes(data=True) if d['y'] in lats and d['x'] in lons and len(list(G.neighbors(n))) == 1] [nodes_mass_increment.update([(list(G.neighbors(n))[0], material_weights.get((d['y'], d['x']))[0])]) \ for n, d in G.nodes(data=True) if d['y'] in lats and d['x'] in lons and len(list(G.neighbors(n))) == 1] if len(list(nodes_coordinates.keys())) != len(stop_points): [nodes_coordinates.update([(n, (d['y'], d['x']))]) for n, d in G.nodes(data=True) if d['y'] in lats and d['x'] in lons] [nodes_mass_increment.update([(n, material_weights.get((d['y'], d['x']))[0])]) \ for n, d in G.nodes(data=True) if d['y'] in lats and d['x'] in lons] Scenario.simulation_edit_graph(G, file_osm) G = Graph.set_node_elevation(G, geotiff) G = Graph.edge_grades(G) #G = Graph.update_weight(G, VEHICLE_MASS) Graph.save_graph_file(G, file_name) return G, nodes_coordinates, nodes_mass_increment
def nodes_data(file_name, stop_points, material_weights, file_osm, geotiff, file): G = ox.load_graphml(file_name) nodes_coordinates = {} nodes_mass_increment = {} try: f = open(file + '.json', "r") dados = json.loads(f.read()) f.close() except: dados = 0 pass dados = dict(dados) tam = len(list(dados.values())) dados = list(dados.values())[:tam-2] [nodes_coordinates.update([(int(d[0][2]), (d[0][0], d[0][1]))]) \ for d in list(dados)] [nodes_mass_increment.update([(int(d[0][2]), int(d[0][3]))]) \ for d in list(dados)] Scenario.simulation_edit_graph(G, file_osm) G = Graph.set_node_elevation(G, geotiff) G = Graph.edge_grades(G) #G = Graph.update_weight(G, VEHICLE_MASS) Graph.save_graph_file(G, file_name) return G, nodes_coordinates, nodes_mass_increment
if __name__ == '__main__': G = ox.graph_from_bbox(-22.796008, -22.843953, -47.054891, -47.107718000000006, network_type='all') stop_points = [(-22.820204, -47.085525), (-22.825029, -47.068495), (-22.824376, -47.070952), (-22.82503, -47.07410), (-22.82504, -47.07730), (-24.992554, -47.069115)] # (-22.816008, -47.075614)] # fig1, ax1 = ox.plot_graph(G, node_size=5, edge_color='#333333', bgcolor='k') # Graph.save_graph_file(G, '../' + MAPS_DIRECTORY, 'test1') weigths = { (-22.816639, -47.074891): (50, 'Kg'), (-22.818317, -47.083415): (30, 'Kg'), (-22.820244, -47.085422): (15, 'Kg'), (-22.823953, -47.087718): (12, 'Kg') } G, nodes_collect_and_coordinates, nodes_collect_and_weights = add_collect_points( G, stop_points, weigths) G = Graph.set_node_elevation(G, '../' + MAPS_DIRECTORY + '22S48_ZN.tif') G = Graph.edge_grades(G) Graph.save_graph_file(G, '../' + MAPS_DIRECTORY, 'test.graphml') # Graph.plot_graph(G) weight = Graph._weight(G, 'weight') distance, route = nx.bidirectional_dijkstra(G, 1000000002, 1000000011, weight) print(route)