Skip to content

Commit

Permalink
fixes sporadic bug in node consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
songololo committed Dec 7, 2023
1 parent dba8cd6 commit 6d8c072
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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.6.3b1'
version = '4.6.3b2'
description = "Computational tools for network-based pedestrian-scale urban analysis"
readme = "README.md"
requires-python = ">=3.10, <3.12"
Expand Down
11 changes: 9 additions & 2 deletions pysrc/cityseer/tools/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,15 @@ def _squash_adjacent(
raise ValueError(f"Attempted to add a duplicate node for node_group {node_group}.")
# iterate the nodes to be removed and connect their existing edge geometries to the new centroid
for nd_key in node_group:
nd_data: NodeData = nx_multigraph.nodes[nd_key]
nd_xy = (nd_data["x"], nd_data["y"])
# iterate the node's existing neighbours
for nb_nd_key in nx.neighbors(nx_multigraph, nd_key):
# no need to rewire the edge if the neighbour is the same as the new node
# this would otherwise result in a zero length edge
# the edge will be dropped once the nd_key is removed
if nb_nd_key == new_nd_name:
continue
# if a neighbour is also going to be dropped, then no need to create new between edges
# an exception exists when a geom is looped, in which case the neighbour is also the current node
if nb_nd_key in node_group and nb_nd_key != nd_key:
Expand All @@ -581,8 +588,6 @@ def _squash_adjacent(
f"for edge {nd_key}-{nb_nd_key}."
)
# orient the LineString so that the geom starts from the node's x_y
nd_data: NodeData = nx_multigraph.nodes[nd_key]
nd_xy = (nd_data["x"], nd_data["y"])
line_coords = util.align_linestring_coords(line_geom.coords, nd_xy)
# update geom starting point to new parent node's coordinates
line_coords = util.snap_linestring_startpoint(line_coords, (new_cent.x, new_cent.y))
Expand All @@ -594,6 +599,8 @@ def _squash_adjacent(
target_nd_key = nb_nd_key
# build the new geom
new_edge_geom = geometry.LineString(line_coords)
if new_edge_geom.length == 0:
raise ValueError(f"Attempted to add a zero length edge from {new_nd_name} to {target_nd_key}")
# check that a duplicate is not being added
dupe = False
if nx_multigraph.has_edge(new_nd_name, target_nd_key):
Expand Down

0 comments on commit 6d8c072

Please sign in to comment.