pyrosm.OSM.to_graph

Contents

pyrosm.OSM.to_graph#

static OSM.to_graph(nodes, edges, graph_type='igraph', direction='oneway', from_id_col='u', to_id_col='v', edge_id_col='id', node_id_col='id', force_bidirectional=False, network_type=None, retain_all=False, osmnx_compatible=True, pandana_weights=['length'], simplify=False, simplify_kwargs=None)#

Export OSM network to routable graph. Supported output graph types are:

  • “igraph” (default),

  • “networkx”,

  • “pandarm”,

  • “pandana” (deprecated; use “pandarm”)

For walking, the output graph will be bidirectional by default (i.e. travel along the street is allowed to both directions). For driving and cycling, one-way streets are taken into account by default and the travel is restricted based on the rules in OSM data (the “oneway” attribute; cycling additionally honours “oneway:bicycle” so that contraflow cycling on one-way streets is modelled correctly).

Set simplify=True to topologically simplify the graph before export: interstitial degree-2 nodes are removed and each intersection-to-intersection chain is collapsed into a single edge that keeps the full geometry. This reduces the graph size while preserving routing distances and is equivalent to osmnx.simplification.simplify_graph.

Parameters:
  • nodes (GeoDataFrame) – GeoDataFrame containing nodes of the road network. Note: Use osm.get_network(nodes=True) to retrieve both the nodes and edges.

  • edges (GeoDataFrame) – GeoDataFrame containing the edges of the road network.

  • graph_type (str) –

    Type of the output graph. Available graphs are:
    • ”igraph” –> returns an igraph.Graph -object.

    • ”networkx” –> returns a networkx.MultiDiGraph -object.

    • ”pandarm” –> returns a pandarm.Network -object.

    • ”pandana” –> returns a pandana.Network -object. (deprecated: pandana is unmaintained and incompatible with NumPy 2 on Windows; use “pandarm” instead. Will be removed in a future release.)

  • direction (str) – Name for the column containing information about the allowed driving directions

  • from_id_col (str) – Name for the column having the from-node-ids of edges.

  • to_id_col (str) – Name for the column having the to-node-ids of edges.

  • edge_id_col (str) – Name for the column having the unique id for edges.

  • node_id_col (str) – Name for the column having the unique id for nodes.

  • force_bidirectional (bool) – If True, all edges will be created as bidirectional (allow travel to both directions).

  • network_type (str (optional)) – Network type for the given data. Determines how the graph will be constructed. The network type is typically extracted automatically from the metadata of the edges/nodes GeoDataFrames. This parameter can be used if this metadata is not available for a reason or another. By default, a bidirectional graph is created for walking and all, and a directed graph for driving and cycling (oneway streets are taken into account; cycling additionally honours oneway:bicycle for contraflow). Possible values are: ‘walking’, ‘cycling’, ‘driving’, ‘driving+service’, ‘all’.

  • retain_all (bool) – if True, return the entire graph even if it is not connected. otherwise, retain only the connected edges.

  • osmnx_compatible (bool (default True)) – if True, modifies the edge and node-attribute naming to be compatible with OSMnx (allows utilizing all OSMnx functionalities). NOTE: Only applicable with “networkx” graph type.

  • pandana_weights (list) – Columns that are used as weights when exporting to Pandana graph. By default uses “length” column.

  • simplify (bool (default False)) – If True, topologically simplify the graph before export: interstitial nodes that only carry geometry (degree-2 pass-throughs) are removed and each chain between intersections/endpoints is collapsed into a single edge that keeps the full geometry. Edge length is summed along the chain and the merged geometry runs from u to v. The result is equivalent to osmnx.simplification.simplify_graph. See pyrosm.graph_simplify.simplify_graph for details.

  • simplify_kwargs (dict (optional)) – Keyword arguments forwarded to pyrosm.graph_simplify.simplify_graph when simplify=True, e.g. edge_attrs_differ (do not merge across a change in the listed columns), node_attrs_include (keep the listed nodes as endpoints), remove_rings, track_merged or length_cols.