def transit_graph(gtfs_paths,
route_types=None,
time_window=None,
agency_ids=None,
boundary=None,
frac=None,
walk_transfer_max_distance=200,
walk_speed_kmph=4,
crs=None)
Create transit network graph from GTFS file(s).
Nodes correspond to transit stops and edges to transit connections between stops. Each node and each edge belongs to only a single transit route. If multiple routes serve the same station, they are depicted as multiple nodes. Edges for walking transfer between nearby nodes of different routes are added. For each node, the global closeness centrality and the number of departures are calculated.
-
gtfs_paths : str or list
Paths to GTFS files.
-
route_types : list, optional
List of transit route types to include in the graph. If None, all service types are include.
-
time_window : list, optional
Pair of ISO 8601-formatted times to include services only within a time window
-
agency_ids : list, optional
List of agencies (according to agency.txt) whose transit services are to be included n the graph. If None, all agencies are included.
-
boundary : shapely.geometry.Polygon, optional
Polygon to filter transit stops by.
-
frac : float, optional
Fraction, allowing to randomly sample a subset of transit routes to be included i the graph.
-
walk_transfer_max_distance : int, optional
Maximum distance in meters to allow walking transfer between transit stops
-
walk_speed_kmph : int, optional
Assumed walking speed in km/h when calculating walking transfer times
-
crs : str, optional
Metric coordinate reference system (CRS) to project transit stops to. If None, apropriate CRS UTM zone is inferred from lat lon bounds.
- networkx.DiGraph
Directional transit network graph.
def nodes_to_df(G)
Convert DiGraph nodes to DataFrame.
G : networkx.DiGraph Transit network graph.
- pandas.DataFrame
DataFrame of nodes including node attributes.
def nodes_to_gdf(G)
Convert DiGraph nodes to GeoDataFrame.
- G : networkx.DiGraph
Transit network graph.
- geopandas.GeoDataFrame
GeoDataFrame of nodes including node attributes and geometries.
def edges_to_df(G)
Convert DiGraph edges to DataFrame.
- G : networkx.DiGraph
Transit network graph.
- pandas.DataFrame
DataFrame of edges including edge attributes.
def edges_to_gdf(G)
Convert DiGraph edges to GeoDataFrame.
- G : networkx.DiGraph
Transit network graph.
- geopandas.GeoDataFrame
GeoDataFrame of edges including edge attributes and geometries.
def graph_to_gdfs(G)
Convert DiGraph nodes and edges to GeoDataFrames.
- G : networkx.DiGraph
Transit network graph.
- geopandas.GeoDataFrame
GeoDataFrame of nodes including node attributes and geometries. geopandas.GeoDataFrame GeoDataFrame of edges including edge attributes and geometries.
def plot_network(G, attr=None, inc_walk_edges=False, adjust_linewith=True)
Plot DiGraph edges with node or edge attribute color coded.
- G : networkx.DiGraph
Transit network graph.
- inc_walk_edges : bool
Include walking transfer edges in plot.
- adjust_linewith : bool
Adjust edge linewidth based on attribute value.
- matplotlib.axes.Axes
Axis of plot.
def plot_route(G, from_node, to_node)
Plot shortest path between two stops and annonate route transfers.
- G : networkx.DiGraph
Transit network graph.
- from_node : str
Stop ID of origin node.
- from_node : str
Stop ID of destination node.
- matplotlib.axes.Axes
Axis of plot.