Simplify¶
-
_clean_merge_mapping
(edge_mapping, new_edge, old_edges, directed)[source]¶ For the two-degree node merge operation, it cleans the new-old edges mapping dictionary by reporting original edges to the newest edge. It makes sure that all edges in the mapping dictionary dict are in the resulting graph.
-
get_dead_ends
(graph, node_filter=<function no_filter>, only_strict=False)[source]¶ Return the list of dead end in the given graph. A dead end is defined as a node having only one neighbor. For directed graphs, a strict dead end is a node having a unique predecessor and no successors. A weak dead end is a node having a unique predecessor that is also its unique successor.
- Parameters
graph (nx.Graph) – Graph to parse.
node_filter – Evaluates to true if a node can be considered as dead end, false otherwise. (Default value = no_filter)
only_strict – If true, remove only strict dead ends. Used only for directed graphs. (Default value = False)
- Returns
List of node name that are dead ends.
- Return type
- Return type
-
remove_dead_ends
(graph, node_filter=<function no_filter>, only_strict=False)[source]¶ Remove dead ends from a given graph. A dead end is defined as a node having only one neighbor. For directed graphs, a strict dead end is a node having a unique predecessor and no successors. A weak dead end is a node having a unique predecessor that is also its unique successor.
- Parameters
graph (nx.Graph) – Graph to simplify
node_filter – Evaluates to true if a node can be removed, false otherwise. (Default value = no_filter)
only_strict – If true, remove only strict dead ends. Used only for directed graphs. (Default value = False)
-
remove_nan_attributes
(graph, remove_nan=True, remove_none=True, copy=False)[source]¶ Remove the nan and None values from nodes and edges attributes.
- Parameters
graph (nx.Graph) – Graph (or subclass)
remove_nan – If true, remove the nan values (test is
val is np.nan
) (Default value = True)remove_none – If true, remove the
None
values (test isval is None
) (Default value = True)copy – If True, a copy of the graph is returned, otherwise the graph is modified inplace. (Default value = False)
- Returns
The modified graph if
copy
is true.- Return type
None or nx.Graph
-
remove_small_connected_components
(graph, minimum_allowed_size)[source]¶ Remove all connected components having strictly less than
minimum_allowed_size
.
-
trim_graph_with_polygon
(graph, polygon, as_view=False, method='intersects')[source]¶ Trim a graph with a given polygon. Keep only the nodes that intersect (or are within) the polygon.
- Parameters
graph (GeoGraph, GeoDiGraph, GeoMultiGraph or GeoMultiDiGraph) – A GeoGraph (or subclass)
polygon (Polygon or MultiPolygon) – A
shapely.Polygon
describing the area to keepas_view (bool) – If
True
, a view of the given graph is returnedmethod (str) – If set to
"intersects"
, theshapely.intersects
is used (keeps nodes and edges that intersects the polygon). If set to"within"
, theshapely.within
is used (keep nodes and edges that are strictly into the polygon). (Default value = “intersects”)
- Returns
The modified graph if
as_view
isTrue
.- Return type
-
two_degree_node_merge
(graph, node_filter=<function no_filter>)[source]¶ Merge edges that connects two nodes with a unique third node.
- Parameters
graph (GeoGraph, GeoDiGraph, GeoMultiGraph or GeoMultiDiGraph) – Graph to modify
node_filter – Evaluates to true if a given node can be merged. (Default value = no_filter)
- Returns
Dictionary indicating for each new edge the merged ones.
- Return type
- Return type
-
two_degree_node_merge_for_directed_graphs
(graph, node_filter=<function no_filter>)[source]¶ Merge edges that connects two nodes with a unique third node. A potential node to merge n must have exactly two different neighbors u and v with one of the following set of edges:
(u, n) and (n, v)
(u, n), (n, u), (n, v) and (v, n)
For the first case, a merging edge (u, v) is added. Under the latter, two edges (u, v) and (v, u) are added. The added edges will have a geometry corresponding to concatenation of the two replaced edges. If a replaced edge doesn’t have a geometry, the added edge will not have a geometry as well. Edges geometries must be well ordered (first node must match with line’s first extremity), otherwise lines concatenation may not be consistent (see
order_well_lines
).- Parameters
graph (GeoDiGraph or GeoMultiDiGraph) – Given graph to modify
node_filter – Evaluates to true if a given node can be merged. (Default value = no_filter)
- Returns
merged_edges – Dictionary indicating for each new edge the merged ones.
- Return type
-
two_degree_node_merge_for_undirected_graphs
(graph, node_filter=<function no_filter>)[source]¶ Merge edges that connects two nodes with a unique third node for undirected graphs. Potential nodes to merge are nodes with two edges connecting two different nodes. If a replaced edge doesn’t have a geometry, the added edge will not have a geometry as well.
- Parameters
graph (GeoGraph or GeoMultiGraph) – Graph to modify
node_filter – Evaluates to true if a given node can be merged. (Default value = no_filter)
- Returns
Dictionary indicating for each new edge the merged ones.
- Return type
- Return type