Last active
June 9, 2019 15:49
-
-
Save wwymak/964dc5b847fc298c66fe4b1e01b7c12e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandana as pdna | |
import pandas as pd | |
berlin_drive_nodes_df = pd.DataFrame([x[1] for x in list(berlin_drive_net.nodes(data=True))])[["x", "y", "osmid"]] | |
# this line is important--your nodes dataframe must have the nodes id as index for pandana to construct the network | |
# properly. Ref https://github.com/UDST/pandana/issues/88 | |
berlin_drive_nodes_df.set_index("osmid", inplace=True) | |
berlin_drive_net_edges = list(berlin_drive_net.edges.data('length')) | |
berlin_drive_net_edges = [{"from": x[0], "to": x[1], "weight": x[2]} for x in berlin_drive_net_edges] | |
berlin_drive_edges_df = pd.DataFrame(berlin_drive_net_edges) | |
# create the pandana network as per http://udst.github.io/pandana/tutorial.html, passing in the x, y | |
# coordinates of the nodes, the node ids of the start and end of edges, and also the 'weight' of each edge | |
# in our use case, this is the distance between nodes | |
pdnet=pdna.Network(berlin_drive_nodes_df["x"], berlin_drive_nodes_df["y"], berlin_drive_edges_df["from"], berlin_drive_edges_df["to"], | |
berlin_drive_edges_df[["weight"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment