Skip to content

Commit

Permalink
handles geom col names; enforces string node keys
Browse files Browse the repository at this point in the history
  • Loading branch information
songololo committed Nov 16, 2023
1 parent ece8fe3 commit 136758f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cityseer"
version = '4.3.0'
version = '4.3.1'
description = "Computational tools for network-based pedestrian-scale urban analysis"
readme = "README.md"
requires-python = ">=3.10, <3.12"
Expand Down
8 changes: 5 additions & 3 deletions pysrc/cityseer/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ def nx_from_cityseer_geopandas(
# after above so that errors caught first
logger.info("Unpacking node data.")
for nd_key, nd_data in tqdm(nodes_gdf.iterrows(), disable=config.QUIET_MODE):
nd_key = str(nd_key)
g_multi_copy.nodes[nd_key]["x"] = nd_data.x
g_multi_copy.nodes[nd_key]["y"] = nd_data.y
if hasattr(nd_data, "live"):
Expand All @@ -917,18 +918,19 @@ def nx_from_cityseer_geopandas(
else:
g_multi_copy.nodes[nd_key]["weight"] = 1
logger.info("Unpacking edge data.")
geom_key = edges_gdf.geometry.name
for _, row_data in tqdm(edges_gdf.iterrows(), disable=config.QUIET_MODE):
g_multi_copy.add_edge(
row_data.nx_start_node_key,
row_data.nx_end_node_key,
str(row_data.nx_start_node_key),
str(row_data.nx_end_node_key),
row_data.edge_idx,
length=row_data.length,
angle_sum=row_data.angle_sum,
imp_factor=row_data.imp_factor,
in_bearing=row_data.in_bearing,
out_bearing=row_data.out_bearing,
total_bearing=row_data.total_bearing,
geom=row_data.geom,
geom=row_data[geom_key],
)
# unpack any metrics written to the nodes
metrics_column_labels: list[str] = [c for c in nodes_gdf.columns if c.startswith("cc_metric")]
Expand Down
6 changes: 6 additions & 0 deletions tests/tools/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,12 @@ def test_nx_from_cityseer_geopandas(primal_graph):
for node_key, node_row in nodes_gdf.iterrows(): # type: ignore
for col_label in column_labels:
assert G_round_trip_nx.nodes[node_key][col_label] == node_row[col_label]
# check that arbitrary geom column name doesn't raise
edges_gdf = edges_gdf.rename_geometry("geommoeg")
G_round_trip_nx = io.nx_from_cityseer_geopandas(
nodes_gdf,
edges_gdf,
)
# test with decomposed
G_decomposed = graphs.nx_decompose(primal_graph, decompose_max=20)
# set live explicitly
Expand Down

0 comments on commit 136758f

Please sign in to comment.