Example #1
0
def test_plots():

    G = ox.graph_from_place('Piedmont, California, USA', network_type='drive', simplify=False)
    G2 = ox.simplify_graph(G, strict=False)

    # test getting colors
    co = ox.get_colors(n=5, return_hex=True)
    nc = ox.get_node_colors_by_attr(G2, 'osmid')
    ec = ox.get_edge_colors_by_attr(G2, 'length')

    # save a plot to disk as png
    fig, ax = ox.plot_graph(G, save=True, file_format='png')

    # save a plot to disk as svg
    G_simplified = ox.simplify_graph(G)
    fig, ax = ox.plot_graph(G_simplified, show=False, save=True, close=True, file_format='svg')

    G_projected = ox.project_graph(G_simplified)
    fig, ax = ox.plot_graph(G_projected)

    fig, ax = ox.plot_graph(G_projected, fig_height=5, fig_width=5, margin=0.05, axis_off=False, bgcolor='y',
                            file_format='png', filename='x', dpi=180, annotate=True, node_color='k', node_size=5,
                            node_alpha=0.1, node_edgecolor='b', node_zorder=5, edge_color='r', edge_linewidth=2,
                            edge_alpha=0.1, use_geom=False, show=False, save=True, close=True)

    fig, ax = ox.plot_figure_ground(G=G_simplified, file_format='png')
    fig, ax = ox.plot_figure_ground(point=(33.694981, -117.841375), file_format='png')
    fig, ax = ox.plot_figure_ground(address='Denver, Colorado, USA', file_format='png')
Example #2
0
def test_plots():

    G = ox.graph_from_place('Piedmont, California, USA', network_type='drive', simplify=False)
    G2 = ox.simplify_graph(G, strict=False)

    # test getting colors
    co = ox.get_colors(n=5, return_hex=True)
    nc = ox.get_node_colors_by_attr(G2, 'osmid')
    ec = ox.get_edge_colors_by_attr(G2, 'length')

    # save a plot to disk as png
    fig, ax = ox.plot_graph(G, save=True, file_format='png')

    # save a plot to disk as svg
    G_simplified = ox.simplify_graph(G)
    fig, ax = ox.plot_graph(G_simplified, show=False, save=True, close=True, file_format='svg')

    G_projected = ox.project_graph(G_simplified)
    fig, ax = ox.plot_graph(G_projected)

    fig, ax = ox.plot_graph(G_projected, fig_height=5, fig_width=5, margin=0.05, axis_off=False, bgcolor='y',
                            file_format='png', filename='x', dpi=180, annotate=True, node_color='k', node_size=5,
                            node_alpha=0.1, node_edgecolor='b', node_zorder=5, edge_color='r', edge_linewidth=2,
                            edge_alpha=0.1, use_geom=False, show=False, save=True, close=True)

    fig, ax = ox.plot_figure_ground(G=G_simplified, file_format='png')
    fig, ax = ox.plot_figure_ground(point=(33.694981, -117.841375), file_format='png')
    fig, ax = ox.plot_figure_ground(address='Denver, Colorado, USA', file_format='png')
Example #3
0
 def plot_graph_route_over_cost(self, path_converted, filename=None):
     ec = ox.get_edge_colors_by_attr(self.planner.graph, 'cost', cmap='plasma', num_bins=100)
     fig, ax = ox.plot_graph(self.kalman.env.graph, fig_height=6, edge_color=ec, node_zorder=2,
                              use_geom=True)
     if filename:
         fig, ax = ox.plot_graph_route(self.planner.graph, path_converted, edge_color=ec, route_alpha=0.3, save=True, filename=filename, )
     else:
         fig, ax = ox.plot_graph_route(self.planner.graph, path_converted, edge_color=ec, route_alpha=0.3)
 def plot_edge_elevation(self):
     G_proj = ox.project_graph(self.G)
     ec = ox.get_edge_colors_by_attr(G_proj,
                                     'grade_abs',
                                     cmap='plasma',
                                     num_bins=100)
     fig, ax = ox.plot_graph(G_proj,
                             fig_height=6,
                             edge_color=ec,
                             edge_linewidth=0.8,
                             node_size=0)
Example #5
0
def test_plots():

    G = ox.graph_from_place('Piedmont, California, USA',
                            network_type='drive',
                            simplify=False)
    G2 = ox.simplify_graph(G, strict=False)
    ec = ox.get_edge_colors_by_attr(G2, 'length')
    fig, ax = ox.plot_graph(G, save=True, file_format='png')

    G_simplified = ox.simplify_graph(G)
    fig, ax = ox.plot_graph(G_simplified,
                            show=False,
                            save=True,
                            close=True,
                            file_format='svg')

    G_projected = ox.project_graph(G_simplified)
    fig, ax = ox.plot_graph(G_projected)

    fig, ax = ox.plot_graph(G_projected,
                            fig_height=5,
                            fig_width=5,
                            margin=0.05,
                            axis_off=False,
                            bgcolor='y',
                            file_format='png',
                            filename='x',
                            dpi=180,
                            annotate=True,
                            node_color='k',
                            node_size=5,
                            node_alpha=0.1,
                            node_edgecolor='b',
                            node_zorder=5,
                            edge_color='r',
                            edge_linewidth=2,
                            edge_alpha=0.1,
                            use_geom=False,
                            show=False,
                            save=True,
                            close=True)
Example #6
0
randomly selected as this is the prototype of our idea'''

count = 0
route = []
for path in nx.all_simple_paths(G=graph_proj,
                                source=orig_node,
                                target=target_node):
    # print(path)
    route.append(path)
    if count == 10:
        break
    count += 1

# ----------------------------------------------------------------> plottina graph for visualization

ec = ox.get_edge_colors_by_attr(graph_proj, attr='length')
# ox.set_title("new1")
ox.plot_graph(graph_proj, edge_color=ec)

fig, ax = ox.plot_graph_routes(graph_proj, route, edge_color='#ffffff')

plt.title("Different paths between source and destination")
plt.tight_layout()

#--------------------------------------------------------------------->Future work<-------------------------------------------------
'''


As we found the paths between source and destination which are randomly selected, we will do this for specific source and destinastion
and based on the paths we got and the information of GPS we will get to know the affected paths (finding the affected path is: we will 
send our rescue team to all the paths we found and get the information from them). From the remaining paths we will get to know the
Example #7
0
biokoGraph = ox.graph_from_place('Bioko', network_type='all')
ox.plot_graph(biokoGraph,fig_height=20)

# import buildings & save to .shp
biokoBldg = ox.buildings_from_place('Bioko')
biokoBldgProj = ox.project_gdf(biokoBldg)
ox.plot_buildings(gdf=biokoBldgProj,bgcolor='#333333',color='w',save=True, show=False, close=True, filename='biokoBldg', dpi=90)
Image('{}/{}.{}'.format('images', 'biokoBldg', 'png'), height=800, width=800)

biokoBldgShp = biokoBldg.drop(labels='nodes',axis=1)
biokoBldgShp.to_file('Desktop/BiokoBldg')

biokoAreas = biokoBldgProj.area

# basic analysis of road network
biokoGraphLength = ox.get_edge_colors_by_attr(biokoGraph, attr='length')
ox.plot_graph(biokoGraph, edge_color=biokoGraphLength,fig_height=30)


# helper funcion to get one-square-mile street networks, building footprints, and plot them
def make_plot(place, point, network_type='drive', bldg_color='orange', dpi=90,
              dist=805, default_width=4, street_widths=None):
    gdf = ox.buildings_from_point(point=point, distance=dist)
    gdf_proj = ox.project_gdf(gdf)
    fig, ax = ox.plot_figure_ground(point=point, dist=dist, network_type=network_type, default_width=default_width,
                                    street_widths=street_widths, save=False, show=False, close=True)
    fig, ax = ox.plot_buildings(gdf_proj, fig=fig, ax=ax, color=bldg_color, set_bounds=False,
                                save=True, show=False, close=True, filename=place, dpi=dpi)
    
    
#place = 'portland_buildings'
Example #8
0
import osmnx as ox
ox.config(log_console=True, use_cache=True)
ox.__version__

# get the street network for san francisco
place = 'San Francisco'
place_query = {'city':'San Francisco', 'state':'California', 'country':'USA'}
G = ox.graph_from_place(place_query, network_type='drive')

# add elevation to each of the nodes, using the google elevation API, then calculate edge grades
G = ox.add_node_elevations(G, api_key=google_elevation_api_key)
G = ox.add_edge_grades(G)

edge_grades = [data['grade_abs'] for u, v, k, data in ox.get_undirected(G).edges(keys=True, data=True)]

avg_grade = np.mean(edge_grades)
print('Average street grade in {} is {:.1f}%'.format(place, avg_grade*100))

med_grade = np.median(edge_grades)
print('Median street grade in {} is {:.1f}%'.format(place, med_grade*100))

# project the street network to UTM
G_proj = ox.project_graph(G)

# get one color for each node, by elevation, then plot the network
nc = ox.get_node_colors_by_attr(G_proj, 'elevation', cmap='plasma', num_bins=20)
fig, ax = ox.plot_graph(G_proj, fig_height=6, node_color=nc, node_size=12, node_zorder=2, edge_color='#dddddd')

# get a color for each edge, by grade, then plot the network
ec = ox.get_edge_colors_by_attr(G_proj, 'grade_abs', cmap='plasma', num_bins=100)
fig, ax = ox.plot_graph(G_proj, fig_height=6, edge_color=ec, edge_linewidth=0.8, node_size=0)