Skip to content

Commit

Permalink
ENH: Use list comprehension instead of map.
Browse files Browse the repository at this point in the history
  • Loading branch information
Taher Chegini committed Nov 23, 2024
1 parent b09c8a4 commit dfd04fc
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions osmnx/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,11 @@ def graph_to_gdfs(
u, v, k, data = zip(*G.edges(keys=True, data=True))

if fill_edge_geometry:
# subroutine to get geometry for every edge: if edge already has
# geometry return it, otherwise create it using the incident nodes
x_lookup = nx.get_node_attributes(G, "x")
y_lookup = nx.get_node_attributes(G, "y")

def _make_edge_geometry(
u: int,
v: int,
data: dict[str, Any],
x: dict[int, float] = x_lookup,
y: dict[int, float] = y_lookup,
) -> LineString:
if "geometry" in data:
return data["geometry"]

# otherwise
return LineString((Point((x[u], y[u])), Point((x[v], y[v]))))

edge_geoms = map(_make_edge_geometry, u, v, data)
coords = {n: (G.nodes[n]["x"], G.nodes[n]["y"]) for n in G}
edge_geoms = (
edata.get("geometry", LineString((coords[u], coords[v])))
for u, v, _, edata in G.edges(keys=True, data=True)
)
gdf_edges = gpd.GeoDataFrame(data, crs=crs, geometry=list(edge_geoms))

else:
Expand Down

0 comments on commit dfd04fc

Please sign in to comment.