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

ENH: support bi-directional roads in gdf_to_nx #357

Merged
merged 5 commits into from
Jun 8, 2022

Conversation

kopytjuk
Copy link
Contributor

@kopytjuk kopytjuk commented May 19, 2022

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:

image

This functionality is helpful for path finding applications in directed graphs, where the same road can be traversed in the opposite direction.

@jGaboardi jGaboardi requested a review from martinfleis May 19, 2022 22:40
@codecov
Copy link

codecov bot commented May 21, 2022

Codecov Report

Merging #357 (0ae017c) into main (c6b9b2d) will decrease coverage by 0.0%.
The diff coverage is 88.9%.

❗ Current head 0ae017c differs from pull request most recent head 6f376a5. Consider uploading reports for the commit 6f376a5 to get more accurate results

Impacted file tree graph

@@           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     
Impacted Files Coverage Δ
momepy/utils.py 98.8% <88.9%> (-0.6%) ⬇️

Copy link
Member

@martinfleis martinfleis left a 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)):
Copy link
Member

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?

Copy link
Contributor Author

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.

@kopytjuk
Copy link
Contributor Author

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.

Agreed, I added a note in the docstring of the function that with oneway-option nx_to_gdf(gdf_to_nx(gdf, directed=True, oneway_column="oneway")) an extended geodataframe is returned.

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.

@kopytjuk
Copy link
Contributor Author

kopytjuk commented Jun 8, 2022

Hello again @martinfleis, am I missing something?

@martinfleis
Copy link
Member

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.

@martinfleis martinfleis changed the title Add bidirectional linestrings (roads) functionality ENH: support bi-directional roads in gdf_to_nx Jun 8, 2022
@martinfleis martinfleis merged commit 319c36a into pysal:main Jun 8, 2022
@martinfleis
Copy link
Member

Thanks a lot @kopytjuk!

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

Successfully merging this pull request may close these issues.

3 participants