Skip to content

Commit

Permalink
handles empty or zero length geoms
Browse files Browse the repository at this point in the history
  • Loading branch information
songololo committed Dec 2, 2024
1 parent cc54180 commit dac0f10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 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.17.1'
version = '4.17.2'
description = "Computational tools for network-based pedestrian-scale urban analysis"
readme = "README.md"
requires-python = ">=3.10, <3.14"
Expand Down
11 changes: 10 additions & 1 deletion pysrc/cityseer/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ def network_structure_from_nx(
f"Expecting LineString geometry but found {line_geom.geom_type} geom for edge "
f"{start_node_key}-{end_node_key}."
)
# cannot have zero or negative length - division by zero
if line_geom.is_empty:
raise TypeError(f"Found empty geom for edge {start_node_key}-{end_node_key}.")
line_len = line_geom.length
if not np.isfinite(line_len) or line_len <= 0:
raise ValueError(
Expand Down Expand Up @@ -1419,6 +1420,14 @@ def _node_key(node_coords):
for edge_idx, edge_row in tqdm(gdf_network.iterrows(), total=len(gdf_network), disable=config.QUIET_MODE):
# generate start and ending nodes
edge_geom = edge_row[geom_key]
# drop empty edges
if edge_geom.is_empty:
logger.warning(f"Dropping empty edge at row index {edge_idx}")
continue
# drop zero length edges
if edge_geom.length == 0:
logger.warning(f"Dropping zero length edge at row index {edge_idx}")
continue
# round to 1cm - assumes 1m units
if len(edge_geom.coords[0]) == 3:
edge_geom = geometry.LineString(
Expand Down

0 comments on commit dac0f10

Please sign in to comment.