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 osmnx_like keyword to gdf_to_nx #359

Closed
martinfleis opened this issue May 25, 2022 · 2 comments
Closed

Add osmnx_like keyword to gdf_to_nx #359

martinfleis opened this issue May 25, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@martinfleis
Copy link
Member

Description / Summary

Our networkx graphs were initially (in 2019) compatible with osmnx graphs. Right now, they are slightly different because the structure on the osmnx side has changed. I suggest adding a osmnx_like keyword to gdf_to_nx which tries to mimic the structure of osmnx graph (mostly adding arbitrarily generated osmid).

Value / benefit

The graph created with gdf_to_nx(osmnx_like=True) can be consumed by any osnmx function. Right now, it sometimes doesn't work.

Implementation details

New keyword, defaulting to False.

We need to check how exactly should the graph look like (I am not fully sure).

Tasks to complete

Once this is done, we also need to ensure that all our graph functions work on both of these objects, no matter the osmnx_like keyword.

@martinfleis martinfleis added the enhancement New feature or request label May 25, 2022
@amorfinv
Copy link
Contributor

amorfinv commented Aug 9, 2022

Hey @gsagostini,

From our conversation today I remembered I had actually done something like this already for my own stuff. So I made a first attempt at how it would look in momepy. see here

At the moment it only makes a MultiDirectedGraph since that is what osmnx.graph_from_gdf() does. However, if you want an undirected graph then it should also add the from and to columns.

From osmnx documentation documentation there are only three requirements so a graph can be used with their functions.

However, you can convert arbitrary node and edge GeoDataFrames as long as 1) gdf_nodes is uniquely indexed by osmid, 2) gdf_nodes contains x and y coordinate columns representing node geometries, 3) gdf_edges is uniquely multi-indexed by u, v, key (following normal MultiDiGraph structure). This allows you to load any node/edge shapefiles or GeoPackage layers as GeoDataFrames then convert them to a MultiDiGraph for graph analysis. Note that any geometry attribute on gdf_nodes is discarded since x and y provide the necessary node geometry information instead.

I also ignored the oneway argument in this first attempt.

@martinfleis
Copy link
Member Author

This has been implemented in #546 using the integer_labels=True flag. That results in an osmnx-compatible graph.

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

No branches or pull requests

2 participants