diff --git a/osmnx/_osm_xml.py b/osmnx/_osm_xml.py index b64f0ad0..20c0c394 100644 --- a/osmnx/_osm_xml.py +++ b/osmnx/_osm_xml.py @@ -228,9 +228,9 @@ def _save_graph_xml( ) warn(msg, category=UserWarning, stacklevel=2) - # raise error if graph has been simplified - if G.graph.get("simplified", False): - msg = "Graph must be unsimplified to save as OSM XML." + # raise error if graph has been simplified or nodes consolidated + if G.graph.get("simplified", False) or G.graph.get("consolidated", False): + msg = "Graph must be unsimplified and unconsolidated to save as OSM XML." raise GraphSimplificationError(msg) # set default filepath if None was provided diff --git a/osmnx/io.py b/osmnx/io.py index bd8ad056..e169de58 100644 --- a/osmnx/io.py +++ b/osmnx/io.py @@ -188,7 +188,10 @@ def load_graphml( raise ValueError(msg) # specify default graph/node/edge attribute values' data types - default_graph_dtypes = {"simplified": _convert_bool_string} + default_graph_dtypes = { + "consolidated": _convert_bool_string, + "simplified": _convert_bool_string, + } default_node_dtypes = { "elevation": float, "elevation_res": float, diff --git a/osmnx/simplification.py b/osmnx/simplification.py index 32976476..06194d95 100644 --- a/osmnx/simplification.py +++ b/osmnx/simplification.py @@ -630,6 +630,10 @@ def _consolidate_intersections_rebuild_graph( # noqa: C901,PLR0912,PLR0915 A rebuilt graph with consolidated intersections and (optionally) reconnected edge geometries. """ + if G.graph.get("consolidated"): # pragma: no cover + msg = "This graph has already been consolidated, cannot consolidate it again." + raise GraphSimplificationError(msg) + # default node attributes to aggregate upon consolidation if node_attr_aggs is None: node_attr_aggs = {"elevation": "mean"} @@ -715,6 +719,9 @@ def _consolidate_intersections_rebuild_graph( # noqa: C901,PLR0912,PLR0915 node_attrs[col] = unique_vals Gc.add_node(cluster_label, **node_attrs) + # mark the graph as having been consolidated + G.graph["consolidated"] = True + if len(G.edges) == 0 or not reconnect_edges: # if reconnect_edges is False or there are no edges in original graph # (after dead-end removed), then skip edges and return new graph as-is