iduedu.simplify_graph

iduedu.simplify_graph(graph, *, keys=None, keep_nodes=None, sum_columns=None)[source]

Merge chains of edges through nodes of degree two into single edges.

Two edges are merged at a node when they are the only edges there, their keys are equal and their directions agree. In an undirected graph, and between two-way edges of a directed graph (the direction column is False), an edge drawn against the chain is turned, so the merged geometry runs from u to v. One-way edges are merged only head to tail, and a one-way edge is never merged with a two-way one. A ring without a junction becomes a loop at its first node.

Parameters:
  • graph (UrbanGraph) – Any graph.

  • keys (Iterable[str] | None) – Edge columns that must be equal along a chain. By default all columns except u, v, k, the geometry and sum_columns; in a directed graph the direction column is among them.

  • keep_nodes (Iterable | None) – Nodes that stay, for example nodes that objects or another table refer to. The nodes a walk graph joins public transport at (type platform or a subway entrance or exit) always stay.

  • sum_columns (Iterable[str] | None) – Columns summed along a chain. By default length_meter, time_min and every time_<name>_min column. The other columns take the values of the first edge.

Return type:

UrbanGraph

Returns:

New graph with the same flags. Nodes inside merged chains are removed; the other nodes keep their ids. In a graph without parallel edges, a chain whose ends another edge already joins stays split at its first inner node.

Raises:

KeyError – If keys or sum_columns name columns the edges do not have.