From dfd04fc3b76f239c1268b4a1d9b5811a0401bc4c Mon Sep 17 00:00:00 2001 From: Taher Chegini Date: Sat, 23 Nov 2024 13:49:48 -0500 Subject: [PATCH] ENH: Use list comprehension instead of map. --- osmnx/convert.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/osmnx/convert.py b/osmnx/convert.py index 2909bc35..354afa9f 100644 --- a/osmnx/convert.py +++ b/osmnx/convert.py @@ -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: