-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating to networkx 2.0 #84
Conversation
More info:
|
1 similar comment
@@ -554,7 +554,7 @@ def plot_graph_route(G, route, bbox=None, fig_height=6, fig_width=None, | |||
lines = [] | |||
for u, v in edge_nodes: | |||
# if there are parallel edges, select the shortest in length | |||
data = min([data for data in G.edge[u][v].values()], key=lambda x: x['length']) | |||
data = min(G.get_edge_data(u, v).values(), key=lambda x: x['length']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be G[u][v].values()
or G.adj[u][v].values()
or G.get_edge_data(u, v).values()
. They are equivalent.
edge_types = [list(edge.values())[0]['highway'] for edge in G_undir.edge[node].values()] | ||
# first, identify all the highway types of this node's incident edges | ||
incident_edges_data = [G_undir.get_edge_data(node, neighbor) for neighbor in G_undir.neighbors(node)] | ||
edge_types = [data[0]['highway'] for data in incident_edges_data] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could stick with what you had replacing G_undir.edge[node]
with G_undir.adj[node]
or G_undir[node]
osmnx/save_load.py
Outdated
# look at this first edge's parallel edges one at a time | ||
for key_other in H.edge[u][v]: | ||
# look at every other edge between u and v, one at a time | ||
for key_other in dict(H[u][v]).keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code H[u][v]
creates a dict. So you don't need the dict/keys parts. Replace G.edge[u][v]
with either G[u][v]
or G.adj[u][v]
(they are equivalent)
osmnx/simplify.py
Outdated
@@ -71,13 +71,13 @@ def is_endpoint(G, node, strict=True): | |||
|
|||
# add all the edge OSM IDs for incoming edges | |||
for u in G.predecessors(node): | |||
for key in G.edge[u][node]: | |||
osmids.append(G.edge[u][node][key]['osmid']) | |||
for key in dict(G[u][node]).keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: could replace G.edge
with G.adj
everywhere in the old code. You can also use G[u][node]
in place of G.edge[u][node]
if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dschult thanks Dan, very helpful.
@@ -243,14 +243,13 @@ def simplify_graph(G_, strict=True): | |||
for u, v in zip(path[:-1], path[1:]): | |||
|
|||
# there shouldn't be multiple edges between interstitial nodes | |||
edges = G.edge[u][v] | |||
if not len(edges) == 1: | |||
if not G.number_of_edges(u=u, v=v) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be: if len(G[u][v]) != 1:
but maybe G.number_of_edges
is clearer.
@@ -509,7 +509,7 @@ def get_route_edge_attributes(G, route, attribute, minimize_key='length'): | |||
for u, v in zip(route[:-1], route[1:]): | |||
# if there are parallel edges between two nodes, select the one with the | |||
# lowest value of minimize_key | |||
data = min([data for data in G.edge[u][v].values()], key=lambda x: x[minimize_key]) | |||
data = min(G.get_edge_data(u, v).values(), key=lambda x: x[minimize_key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same options as above: G.edge
could be replaced by G
, G.adj
or by using G.get_edge_data
. They are equivalent.
Migrating OSMnx from networkx 1.x to networkx 2.0's new API.