diff --git a/CHANGELOG.md b/CHANGELOG.md index f93dd49c0..e94b90df7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - fix a bug arising from the save_graph_xml function (#1093) - warn user if their query area is significantly larger than max query area size (#1101) - refactor utils_geo module and deprecate quadrat_width and min_num function arguments (#1100) -- under-the-hood code clean-up (#1092 #1099) +- under-the-hood code clean-up (#1092 #1099 #1103) ## 1.8.0 (2023-11-30) diff --git a/osmnx/truncate.py b/osmnx/truncate.py index 58f4c6069..8fc2409c7 100644 --- a/osmnx/truncate.py +++ b/osmnx/truncate.py @@ -21,11 +21,10 @@ def truncate_graph_dist(G, source_node, max_dist=1000, weight="length", retain_a G : networkx.MultiDiGraph input graph source_node : int - the node in the graph from which to measure network distances to other - nodes - max_dist : int - remove every node in the graph that is greater than this distance from - source_node (along the network) + node in graph from which to measure network distances to other nodes + max_dist : float + remove every node in the graph that is greater than this distance (in + same units as `weight` attribute) along the network from `source_node` weight : string graph edge attribute to use to measure distance retain_all : bool diff --git a/osmnx/utils_graph.py b/osmnx/utils_graph.py index df60642d7..fdca06db5 100644 --- a/osmnx/utils_graph.py +++ b/osmnx/utils_graph.py @@ -45,21 +45,21 @@ def graph_to_gdfs(G, nodes=True, edges=True, node_geometry=True, fill_edge_geome msg = "graph contains no nodes" raise ValueError(msg) - nodes, data = zip(*G.nodes(data=True)) + uvk, data = zip(*G.nodes(data=True)) if node_geometry: # convert node x/y attributes to Points for geometry column - geom = (Point(d["x"], d["y"]) for d in data) - gdf_nodes = gpd.GeoDataFrame(data, index=nodes, crs=crs, geometry=list(geom)) + node_geoms = (Point(d["x"], d["y"]) for d in data) + gdf_nodes = gpd.GeoDataFrame(data, index=uvk, crs=crs, geometry=list(node_geoms)) else: - gdf_nodes = gpd.GeoDataFrame(data, index=nodes) + gdf_nodes = gpd.GeoDataFrame(data, index=uvk) gdf_nodes.index = gdf_nodes.index.rename("osmid") utils.log("Created nodes GeoDataFrame from graph") if edges: if not G.edges: # pragma: no cover - msg = "graph contains no edges" + msg = "Graph contains no edges" raise ValueError(msg) u, v, k, data = zip(*G.edges(keys=True, data=True)) @@ -70,15 +70,15 @@ def graph_to_gdfs(G, nodes=True, edges=True, node_geometry=True, fill_edge_geome x_lookup = nx.get_node_attributes(G, "x") y_lookup = nx.get_node_attributes(G, "y") - def _make_geom(u, v, data, x=x_lookup, y=y_lookup): + def _make_edge_geometry(u, v, data, x=x_lookup, y=y_lookup): if "geometry" in data: return data["geometry"] # otherwise return LineString((Point((x[u], y[u])), Point((x[v], y[v])))) - geom = map(_make_geom, u, v, data) - gdf_edges = gpd.GeoDataFrame(data, crs=crs, geometry=list(geom)) + edge_geoms = map(_make_edge_geometry, u, v, data) + gdf_edges = gpd.GeoDataFrame(data, crs=crs, geometry=list(edge_geoms)) else: gdf_edges = gpd.GeoDataFrame(data)