benchmark-urbanism / cityseer-api

Computational tools for urban analysis
https://cityseer.benchmarkurbanism.com
GNU Affero General Public License v3.0
90 stars 5 forks source link

Add networkx conversion from momepy street network? #80

Open songololo opened 1 year ago

songololo commented 1 year ago

@martinfleis

I'm wondering about adding a conversion function for a momepy street network GeoDataFrame to cityseer compatible networkx MultiGraph .

Here is an initial sketch of what this might look like: momepy_to_cityseer

This would mainly be intended for people who want to:

I'm curious what your thoughts are on things to take into account so that this is useful, e.g.

There are probably other things but that's all that comes to mind for now...

martinfleis commented 1 year ago

This would certainly be useful. I would probably also be keen to replace networkx with cityseer as an engine for some of our functions internally.

would there be use cases where people might want to do a round-trip

I suppose so.

would there be more interest in going straight from a GeoDataFrame or would there be cases where it is better to go from a momepy formatted networkx Graph

That doesn't matter much imho. GeoDataFrame is the primary structure so having I/O with that is probably better than going via Graph.

cc @JGaboardi

songololo commented 10 months ago

Added a io.nx_from_generic_geopandas method which can ingest LineString GeoPandas data frames and covert them to networkX graphs with geom attributes on the edges. This works for ingesting most LineString DataFrames but let me know if it would help to have a io.nx_from_momepy_geopandas method with custom logic for momepy.

Example added at momepy_to_cityseer.ipynb.

martinfleis commented 10 months ago

How different is cityseer-compatible graph from that created with momepy.gdf_to_nx? If we want to optionally depend on cityseer to do centralities, which I think we want, we would need to go from the graph to cityseer structure rather than from geodataframe. Otherwise we'd need to convert graph to geodataframe to create graph again.