-
Notifications
You must be signed in to change notification settings - Fork 61
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
ENH: support bi-directional roads in gdf_to_nx #357
Conversation
Codecov Report
@@ Coverage Diff @@
## main #357 +/- ##
=======================================
- Coverage 95.9% 95.8% -0.0%
=======================================
Files 13 13
Lines 2811 2818 +7
=======================================
+ Hits 2695 2701 +6
- Misses 116 117 +1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! This is surely useful. I've left two notes in the code.
If you want, you can also add this to the user guide page http://docs.momepy.org/en/stable/user_guide/graph/convert.html. (not strictly needed though).
One more thing we should certainly note - when you do this, gdf_to_nx
-> nx_to_gdf
will not roundtrip as the gdf coming from the bidirectional graph will contain duplicated geometries. That needs to be documented and we may even think about a way of dealing with this when needed.
momepy/utils.py
Outdated
@@ -229,7 +239,12 @@ def gdf_to_nx( | |||
fields = list(gdf_network.columns) | |||
|
|||
if approach == "primal": | |||
_generate_primal(net, gdf_network, fields, multigraph) | |||
if oneway_column and ((not directed) and (not multigraph)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could in theory work also for networkx.DiGraph
, not only MultiDiGraph
, right? Can we allow it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, removed the restriction.
Agreed, I added a note in the docstring of the function that with oneway-option Regarding the user guide, I would prefer a separate PR for that, I guess writing it and generating images will be more work than this PR - if it is OK for you, I would leave this PR as it is. |
Hello again @martinfleis, am I missing something? |
Sorry, long backlog of open source tasks :D. I think it is ready to go. I'll give it another look later today and merge unless I find some issue. |
Thanks a lot @kopytjuk! |
Some road sections can be passed in a bidirectional manner. Either the user has to preprocess his GeoDataFrame (to add an additional LineString in a opposite direction) or we can introduce a function where based on a boolean column, a user can specify which linestrings (roads) are
oneway
or not:This functionality is helpful for path finding applications in directed graphs, where the same road can be traversed in the opposite direction.