How to do angular closeness centrality from a shapefile #462
Unanswered
felipetavares80
asked this question in
Q&A
Replies: 1 comment 13 replies
-
Hi @felipetavares80, First question - which version of momepy do you have? There was a bug in creation of angular graph recently (fixed in the latest release). Second - what makes you think it matches topological calculation? See import geopandas as gpd
import osmnx as ox
import networkx as nx
import momepy
# load Shapefiles as node/edge GeoDataFrames indexed as described in OSMnx docs
gdf_nodes = gpd.read_file('./teste/nodes.shp').set_index('osmid')
gdf_edges = gpd.read_file('./teste/edges.shp').set_index(['u', 'v', 'key'])
# Extract columns x e y coordinates from points
gdf_nodes['x'] = gdf_nodes.geometry.x
gdf_nodes['y'] = gdf_nodes.geometry.y
# convert the node/edge GeoDataFrames to a MultiDiGraph
graph_attrs = {'crs': 'epsg:32625', 'simplified': True}
#G2 = ox.graph_from_gdfs(gdf_nodes, gdf_edges)
G2 = ox.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs)
# saving a gdf and letting momepy do the conversion back to the graph.
edges = ox.graph_to_gdfs(G2, nodes=False, edges=True,
node_geometry=False, fill_edge_geometry=True)
dual = momepy.gdf_to_nx(edges, approach='dual')
# measure with angle as a weight
dual = momepy.closeness_centrality(dual, weight='angle')
# measure without weight - topological
dual = momepy.closeness_centrality(dual, name="topological")
dual_gdf = momepy.nx_to_gdf(dual, points=False)
print(dual_gdf[["closeness", "topological"]].head()) You can see that the values are different
Which is also shown on plots: dual_gdf.plot("closeness") dual_gdf.plot("topological") It seems to work as expected on my side, so I may need a bit more info to see the issue.
How do you do the manual calculation? |
Beta Was this translation helpful? Give feedback.
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone.
I'm trying to do a angular weighted closeness centrality from a segmented road map.
I'm importing it from osmnx, simplifying the segments by Douglas-Peucker on Qgis, extracting the points and creating a graph for momepy closeness centrality analysis.
I did the graph but it seems that the results do not match the manual calculations when I set the angular option for closeness centrality. It matches for topological but not for angular.
I don't know if I'm doing something wrong on manual calculations or in the coding, but 'll appreciate a help on this.
Thanks in advance!
All the Best.
The Codes, the manual calculations document and the shapefiles is attached.
angularclosenesspack.zip
Beta Was this translation helpful? Give feedback.
All reactions