Skip to content

Commit fe0b64b

Browse files
committed
Set id attribute directly in graph
1 parent 97a0977 commit fe0b64b

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/dsf/python/cartography.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
"""
2-
@file cartography.py
3-
@brief Cartography utilities for retrieving and processing OpenStreetMap data.
4-
5-
This module provides functions to download and process street network data
6-
from OpenStreetMap using OSMnx, with support for graph simplification and
7-
standardization of attributes.
8-
"""
9-
101
import networkx as nx
112
import osmnx as ox
123

@@ -129,6 +120,10 @@ def get_cartography(
129120
else:
130121
G[u][v][k][key] = value
131122

123+
# Add id to edges
124+
for i, (u, v, k) in enumerate(G.edges(keys=True)):
125+
G[u][v][k]["id"] = i
126+
132127
# Standardize node attributes in the graph
133128
nodes_to_update = []
134129
for node, data in G.nodes(data=True):
@@ -188,9 +183,8 @@ def get_cartography(
188183
# Convert back to MultiDiGraph temporarily for ox.graph_to_gdfs compatibility
189184
gdf_nodes, gdf_edges = ox.graph_to_gdfs(G)
190185

191-
# Reset index and add edge id
186+
# Reset index and rename columns (id already exists from graph)
192187
gdf_edges.reset_index(inplace=True)
193-
gdf_edges["id"] = gdf_edges.index
194188
gdf_edges.rename(columns={"u": "source", "v": "target"}, inplace=True)
195189
gdf_edges.drop(columns=["key"], inplace=True, errors="ignore")
196190

0 commit comments

Comments
 (0)