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
keysare equal and their directions agree. In an undirected graph, and between two-way edges of a directed graph (the direction column isFalse), an edge drawn against the chain is turned, so the merged geometry runs fromutov. 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 exceptu,v,k, the geometry andsum_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 (typeplatform or a subway entrance or exit) always stay.sum_columns (
Iterable[str] |None) – Columns summed along a chain. By defaultlength_meter,time_minand everytime_<name>_mincolumn. The other columns take the values of the first edge.
- Return type:
- 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
keysorsum_columnsname columns the edges do not have.