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

Relationship between momepy and cityseer #348

Open
martinfleis opened this issue Mar 15, 2022 · 1 comment
Open

Relationship between momepy and cityseer #348

martinfleis opened this issue Mar 15, 2022 · 1 comment

Comments

@martinfleis
Copy link
Member

@songololo created a great package called cityseer that has a some degree of overlap with street network stuff we are doing here. It implements centrality analysis using numba, so it is way faster and parallelised. In #346 we started a discussion on possible interface between cityseer and momepy.

cityseer has a very different API and approach so I am not sure to which degree we will be able to use it internally instead of slow networkx algorithms. We should explore that figure out the best way of linking both libraries.

This snippet is able to create cityseer object from momepy-generated graph.

import geopandas
import momepy
import networkx as nx

from cityseer.metrics.networks import NetworkLayerFromNX

edges = geopandas.read_file("/Users/martin/Downloads/network_prg.gpkg")
primal = momepy.gdf_to_nx(edges)

x = {}
y = {}

for node in primal.nodes():
    x[node] = node[0]
    y[node] = node[1]
nx.set_node_attributes(primal, x, 'x')
nx.set_node_attributes(primal, y, 'y')

for u, v, k, data in primal.edges.data(keys=True):
      primal[u][v][k]['geom'] = data["geometry"]

net = NetworkLayerFromNX(primal, distances=[400])
@songololo
Copy link
Contributor

songololo commented Apr 10, 2022

@martinfleis thanks for the snippet.

This seems to work on my end except I couldn't find a copy of the network_prg.gpkg file so I've used the bubenec dataset for now via:

edges = geopandas.read_file(momepy.datasets.get_path("bubenec"), layer='streets')

It would be possible to skip the networkX representation and go directly from geopandas to numpy arrays, but some drawbacks would be:

  • We'd need to loop through the dataframe regardless to find unique network nodes.
  • It would be necessary to compute the edge lengths, start / end nodes, angular change, and entry / exit angular bearings for the cityseer edge data. cityseer computes this under the hood if importing via networkX representations, so may as well stick with that approach unless advantages envisioned going directly?

cityseer measures are computed in "localised network space", so it is looking from the inside-out (points on the street network) instead of outside-in (aerial 2d map representation). The centralities, accessibilities, mixed-uses, and statistics are therefore computed relative to network distances computed relative to sampled points along the street network (depending on the level of network decomposition chosen). So, if converting back to geopandas it would need to be decided whether to simply keep the data arrays as a point-based geopandas dataframe (which could be created really simply from the raw numpy arrays), else whether to interpolate these datapoints back to the original network edges (which would lose the granularity of observations).

What could perhaps be useful to end-users is to use cityseer's network-based landuse and statistical aggregation methods to compute network-based aggregations or averages of morphological data computed in momepy. This might be useful where trying to weld network centralities, landuse accessibilities, and spatial morphology measures to points of observation for subsequent correlational or data modelling / ML steps. The conversion of data to cityseer is relatively simple and basically requires arrays or python dictionaries of x and y along with arrays of either numerical or categorical descriptors, depending on the data.

If this would be useful, I could draft an example workflow for how to convert network data along with numerical / categorical data to cityseer data structures.

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

2 participants