Skip to content

Commit

Permalink
Merge pull request #1103 from gboeing/release
Browse files Browse the repository at this point in the history
a couple fixes to include in the 1.8.1 release
  • Loading branch information
gboeing authored Dec 30, 2023
2 parents 918ff22 + c29fa59 commit e658190
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 4 additions & 5 deletions osmnx/truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions osmnx/utils_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit e658190

Please sign in to comment.