gboeing / osmnx-examples

Gallery of OSMnx tutorials, usage examples, and feature demonstations.
https://osmnx.readthedocs.io
MIT License
1.5k stars 519 forks source link

fix: isocrones are not taking into account the time #59

Closed pareyesv closed 1 year ago

pareyesv commented 1 year ago

This issue tracker is for proposing new examples or specific changes to existing examples. Please ask "how-to" questions on https://stackoverflow.com/ instead. If you're having trouble with OSMnx, please open an issue at the OSMnx repo: https://github.com/gboeing/osmnx/issues

Before you proceed, please read the contributing guidelines in this repo's CONTRIBUTING.md.

Any issues opened here will be automatically closed unless they propose new examples or specific changes to existing examples.

PRs welcome for new examples!


According to the guidelines above, I think this issue proposes specific changes to existing examples.

Regarding 13-isolines-isochrones.ipynb, the following cell:

# add an edge attribute for time in minutes required to traverse each edge
meters_per_minute = travel_speed * 1000 / 60  # km per hour to m per minute
for _, _, _, data in G.edges(data=True, keys=True):
    data["time"] = data["length"] / meters_per_minute

the cell is not assigning the attribute time to the edges in G.

Then, ego_graph is not taking into account time:

for trip_time, color in zip(sorted(trip_times, reverse=True), iso_colors):
    subgraph = nx.ego_graph(G, center_node, radius=trip_time, distance="time")
    for node in subgraph.nodes():
        node_colors[node] = color

Actually, ego_graph should fail, but it doesn't raise an error.

Consider changing the for-loop cell with the following:

# add an edge attribute for time in minutes required to traverse each edge
meters_per_minute = travel_speed * 1000 / 60  # km per hour to m per minute
time_attr = {(x, y , z): data["length"] / meters_per_minute 
                            for x, y, z, data in G.edges(data=True, keys=True)}
nx.set_edge_attributes(G, time_attr, name="time")
gboeing commented 1 year ago

the cell is not assigning the attribute time to the edges in G

Yes it is. You can see the new time edge attributes if you run this line after that cell:

nx.get_edge_attributes(G, "time")