Example #1
0
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
Example #2
0
def plot_edge_grades():
    files_map = '../data/maps/m43.96267779776494_m19.944747838679202_m43.929659815391865_m19.905049264605925.graphml'
    G = ox.load_graphml(files_map)

    max_lat = -12.934333867695516
    min_lat = -12.961083555974895
    max_lon = -38.473331269107426
    min_lon = -38.49996781691653

    name_geotiff = '../data/maps/19S45_ZN.tif'
    G = ox.graph_from_bbox(max_lat,
                           min_lat,
                           max_lon,
                           min_lon,
                           network_type='all')
    G = Graph.set_node_elevation(G, name_geotiff)
    # deadends = [(u, v) for u, v, k, data in G.edges(keys=True, data=True) if data['highway'] == '']
    # print(deadends)
    # G2.remove_nodes_from(deadends)
    G = Graph.edge_grades(G)
    G_proj = ox.project_graph(G)
    ec = ox.plot.get_edge_colors_by_attr(G_proj,
                                         "grade",
                                         cmap="plasma",
                                         num_bins=5,
                                         equal_size=True)
    fig, ax = ox.plot_graph(G_proj,
                            edge_color=ec,
                            edge_linewidth=0.5,
                            node_size=0,
                            bgcolor="w")
Example #3
0
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
Example #4
0
def plot_elevation_belem():

    files_map = '../data/maps/m48.488877797764935_m1.484547838679201_m48.45585981539186_m1.4448492646059234.graphml'
    G = ox.load_graphml(files_map)

    max_lat = -1.449
    min_lat = -1.479
    max_lon = -48.462
    min_lon = -48.488

    name_geotiff = '../data/maps/01S495ZN.tif'
    G = ox.graph_from_bbox(max_lat,
                           min_lat,
                           max_lon,
                           min_lon,
                           network_type='all')
    G = Graph.set_node_elevation(G, name_geotiff)
    G = Graph.edge_grades(G)
    # G_proj = ox.project_graph(G)
    nc = ox.plot.get_node_colors_by_attr(G,
                                         'elevation',
                                         cmap='plasma',
                                         num_bins=10)  # , start=0, stop=1
    cmap = plt.cm.get_cmap('plasma')
    print(
        "belem",
        max(list(nx.get_node_attributes(G, 'elevation').values())) -
        min(list(nx.get_node_attributes(G, 'elevation').values())))
    norm = plt.Normalize(
        vmin=min(list(nx.get_node_attributes(G, 'elevation').values())),
        vmax=max(list(nx.get_node_attributes(G, 'elevation').values())))
    sm = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)
    sm.set_array([])

    fig, ax = ox.plot_graph(G,
                            node_color=nc,
                            node_size=45,
                            edge_linewidth=0.7,
                            bgcolor='w',
                            show=False)
    # pad: position of colorbar, shrink=.92: colorbar size
    cb = fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap),
                      ax=ax,
                      orientation='vertical',
                      shrink=.94,
                      fraction=0.15,
                      pad=-0.0001)
    cb.ax.tick_params(labelsize=25)
    cb.set_label('Elevação (m)', fontsize=25, labelpad=23, fontweight='bold')
    plt.show()
Example #5
0
def plot_elevation():

    files_map = '../data/maps/m38.49905230272549_m12.960541036813272_m38.47398437502447_m12.935229804750517.graphml'
    G = ox.load_graphml(files_map)

    max_lat = -12.934333867695516
    min_lat = -12.961083555974895
    max_lon = -38.473331269107426
    min_lon = -38.49996781691653

    name_geotiff = '../data/maps/12S39_ZN.tif'
    G = ox.graph_from_bbox(max_lat,
                           min_lat,
                           max_lon,
                           min_lon,
                           network_type='all')
    G = Graph.set_node_elevation(G, name_geotiff)
    G = Graph.edge_grades(G)
    # G_proj = ox.project_graph(G)
    nc = ox.plot.get_node_colors_by_attr(G,
                                         'elevation',
                                         cmap='plasma',
                                         num_bins=10)  # , start=0, stop=1
    cmap = plt.cm.get_cmap('plasma')
    #norm = plt.Normalize(vmin= 0, vmax=max(list(nx.get_node_attributes(G, 'elevation').values())) - min(list(nx.get_node_attributes(G, 'elevation').values())))
    print(
        "Salvador",
        max(list(nx.get_node_attributes(G, 'elevation').values())) -
        min(list(nx.get_node_attributes(G, 'elevation').values())))
    norm = plt.Normalize(
        vmin=min(list(nx.get_node_attributes(G, 'elevation').values())),
        vmax=max(list(nx.get_node_attributes(G, 'elevation').values())))
    sm = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)
    sm.set_array([
        min(list(nx.get_node_attributes(G, 'elevation').values())), 10, 20, 30,
        40, 50, 60, 70, 80, 85
    ])

    figsize = (20, 20)
    fig, ax = ox.plot_graph(G,
                            node_color=nc,
                            node_size=35,
                            edge_linewidth=0.7,
                            bgcolor='w',
                            show=False)

    fig, ax = ox.plot_graph(G,
                            ax=ax,
                            node_color=nc,
                            node_size=35,
                            edge_linewidth=0.7,
                            bgcolor='w',
                            show=False)
    #plt.axis([-38.49996781691653, -38.473331269107426, -12.961083555974895, -12.934333867695516],option='on')
    #ax.axis('on')
    #ax.set(xlim=(-38.49996781691653, -38.473331269107426), ylim=(-12.961083555974895, -12.934333867695516), option='on')

    # pad: position of colorbar, shrink=.92: colorbar size
    cb = fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap),
                      ax=ax,
                      orientation='vertical',
                      shrink=.94,
                      fraction=0.15,
                      pad=-0.0001)
    cb.ax.tick_params(labelsize=25)
    cb.set_label('Altitude [m]', fontsize=25, labelpad=23, fontweight='bold')
    #ax.set_xticks(x)
    plt.show()
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)