Skip to content
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 function to merge parallel roads #1161

Open
3 tasks done
EwoutH opened this issue Apr 18, 2024 · 3 comments
Open
3 tasks done

Add function to merge parallel roads #1161

EwoutH opened this issue Apr 18, 2024 · 3 comments

Comments

@EwoutH
Copy link
Contributor

EwoutH commented Apr 18, 2024

Contributing guidelines

  • I understand the contributing guidelines

Documentation

  • My proposal is not addressed by the documentation or examples

Existing issues

  • Nothing similar appears in an existing issue

What problem does your feature proposal solve?

OSMnx currently has two simplifications options:

  • simplify_graph
  • consolidate_intersections

I think there is a use case for a third one: merge_parallel_edges. It does exactly what it says: If you have multiple parallel edges – both starting and ending at the same node – it merges it to a single edge. This can be very useful for more mesoscopic models that don't need the extensive detail of for example multiple parallel highways.

What is your proposed solution?

Introduce a merge_parallel_edges function to simplify MultiDiGraphs into DiGraphs by merging parallel edges.

Some considerations:

  • NetworkX doesn’t have a built-in function for converting to DiGraph (that gives any control over which edges to keep or how to merge)
  • Some attributes should be nicely aggerated – for example, lane count can be summed
  • You might want to have an argument to exclude some edges from merging – for example if the max_speed is different (then you won’t end up with a clean DiGraph though)
  • In most cases, you want to merge parallel edges after consolidating intersections

What alternatives have you considered?

Manual pre-OSMnx manipulation of graph data to merge edges is inefficient and prone to errors. It also doesn't handle merging attributes cleanly.

Additional context

A basic API outline:

def merge_parallel_edges(G, attribute_merge_strategy={'lanes': 'sum'}, exclude_criteria=None):
    """
    Merges parallel edges in G. Allows attribute aggregation and exclusion based on criteria.
    """
    # Placeholder for implementation

CC @anastassiavybornova, @martinfleis, @jdmcbr and @jGaboardi

@martinfleis
Copy link
Contributor

Some relevant discussion #450 (comment). I also had a short email exchange with @gboeing at the time but it lead to no result apart from some explorations (available in https://github.com/martinfleis/network_simplification).

@gboeing
Copy link
Owner

gboeing commented Apr 26, 2024

Introduce a merge_parallel_edges function to simplify MultiDiGraphs into DiGraphs by merging parallel edges.

Note that the convert module's to_digraph function currently does similar: converting a MultiDiGraph to a DiGraph by choosing between parallel edges by minimizing some weight attribute. This does not aggregate attributes across the parallel edges.

@gboeing
Copy link
Owner

gboeing commented May 27, 2024

In light of my prior comment and @martinfleis comment, I'm inclined to either:

  1. close this issue because OSMnx already has the functionality to convert a MultiDiGraph to a DiGraph by choosing between parallel edges by minimizing some weight attribute, or

  2. add just a limited enhancement to give the existing convert.to_digraph the ability to aggregate attributes across the parallel edges if this is truly useful for general use cases

As noted above, in prior conversation with @martinfleis, it is nontrivial to address this problem well (from both topological and geometric perspectives) and OSMnx may not be the right home (though I'm potentially open to it) for such functionality if a robust and generalizable algorithm is eventually developed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants