I extracted a list of nodes from Open Street Map using astar_path from Networkx. I am trying to create a geopandas data frame the path with that list of nodes. I am able to create a graph from the list of nodes. But when I try to create the geopandas data frame using osmnx, I get the following error: “KeyError: ‘crs'”
Steps to replicate error
Step 1: Extract a path using Networkx astar_path
path_nodes = nx.astar_path(osm_network_data, origin_node, destination_nodes, heuristic=None, weight='length')
path_nodes is a list of nodes
path_nodes
[122962284,
122962281,
353309442,
7887187150,
8460053580]
Step 2: Create a graph using Networkx Graph()
path = nx.Graph()
for i in range(0, len(routes[0])):
path.add_node(path_nodes[i])
This successfully creates a graph object.
Step 3: Create a geopandas data frame using osmnx graph_to_gdf (ERROR)
ox.graph_to_gdfs(path, nodes=True, edges=True, node_geometry=True, fill_edge_geometry=True)
Error message:
KeyError Traceback (most recent call last)
Cell In[181], line 1
—-> 1 ox.graph_to_gdfs(path, nodes=True, edges=True, node_geometry=True, fill_edge_geometry=True)
File /usr/share/anaconda3/envs/ox/lib/python3.12/site-packages/osmnx/utils_graph.py:41, in graph_to_gdfs(G, nodes, edges, node_geometry, fill_edge_geometry)
15 def graph_to_gdfs(G, nodes=True, edges=True, node_geometry=True, fill_edge_geometry=True):
16 “””
17 Convert a MultiDiGraph to node and/or edge GeoDataFrames.
18
(…)
39 following normal MultiDiGraph structure.
40 “””
—> 41 crs = G.graph[“crs”]
43 if nodes:
44 if not G.nodes: # pragma: no cover
KeyError: ‘crs’