-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add node_attrs_include param to simplify_graph to flexibly relax strictness #1145
Conversation
@anastassiavybornova @csebastiao @jGaboardi based on your recent comments in #625, I'm pinging you here as you may be interested in this PR. Any comments welcome. |
@gboeing Thanks for the ping. I really like the |
And just to note, the new This would be the default graph simplification result: import osmnx as ox
G = ox.graph.graph_from_place("Piedmont, CA, USA", network_type="drive", simplify=False)
len(G) # 2918
Gs = ox.simplification.simplify_graph(G)
len(Gs) # 377 But let's say, for example, that you wanted to only relax simplification for stop signs (i.e., nodes where highway=stop). Instead you'd just use: for node, data in G.nodes(data=True):
if data.get("highway") == "stop":
data["stop"] = True
Gs = ox.simplification.simplify_graph(G, node_attrs=["stop"])
len(Gs) # 456 This method of marking a node for retention is infinitely configurable. For example, if you want to make sure you retain all nodes denoting stop signs or uncontrolled junctions, you could use: for node, data in G.nodes(data=True):
if data.get("highway") == "stop" or data.get("junction") == "uncontrolled":
data["keep"] = True
Gs = ox.simplification.simplify_graph(G, node_attrs=["keep"])
len(Gs) |
Thank you for the ping @gboeing ! As @jGaboardi said the If I have some comment to have maybe it's that I'm wondering if the semantic symmetry of |
Thanks @csebastiao. I had the same conundrum. I too prefer succinct param names, but perhaps it would be best to differentiate them somehow. Maybe just calling the latter |
Maybe even |
@jGaboardi I like that. Nice and clear. Let's use it. |
…differ, improve docstrings and comments
I ended up renaming |
Reasonable and clear. |
The first pre-release OSMnx v2 beta has been released. Testers needed! See #1123 for details. |
This PR addresses #625 and #1127, and builds on #1117.
It adds a
node_attrs_include
param to thesimplification.simplify_graph
function to flexibly relax graph simplification strictness. If a node has one or more of the attributes innode_attrs_include
, it will always be marked as an endpoint. This is useful for capturing the presence of stop signs, traffic signals, and pedestrian crossings in your model of the street network by allowing you to retain these nodes in a simplified graph even if they do not represent a junction of multiple streets. This is often the case with nodes that digitize a traffic signal, for instance, just off the intersection itself.It also renames the relatively new
endpoint_attrs
param (introduced in #1117) toedge_attrs_differ
for consistent and clear naming, given the new param. Theendpoint_attrs
param name will be deprecated (#1146) in the next v1 release and removed in the v2.0.0 release.