Skip to content

Commit

Permalink
dedidcated minimal tests -- nodes.weld_edges() (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
jGaboardi authored Oct 23, 2024
1 parent 592aef2 commit 35bd6a0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
21 changes: 18 additions & 3 deletions sgeop/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,25 @@ def get_components(
return labels.values


def weld_edges(edgelines, ignore=None):
"""lightweight version of remove_false_nodes
def weld_edges(
edgelines: list | np.ndarray | gpd.GeoSeries,
ignore: None | gpd.GeoSeries = None,
) -> list:
"""Combine lines sharing an endpoint (if only 2 lines share that point).
Lightweight version of ``remove_false_nodes()``.
Parameters
----------
edgelines : list | np.ndarray | gpd.GeoSeries
Collection of line objects.
ignore : None | gpd.GeoSeries = None
Nodes to ignore when welding components.
optionally ignore some nodes - do not weld lines
Returns
-------
list | np.ndarray | gpd.GeoSeries
Resultant welded ``edgelines`` if more than 1 passed in, otherwise
the original ``edgelines`` object.
"""
if len(edgelines) < 2:
return edgelines
Expand Down
50 changes: 50 additions & 0 deletions sgeop/tests/test_nodes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import itertools

import geopandas.testing
Expand Down Expand Up @@ -254,3 +255,52 @@ def test_snap_n_split(edge, split_point, tol, known):
def test_get_components(edgelines, ignore, known):
observed = sgeop.nodes.get_components(edgelines, ignore=ignore)
numpy.testing.assert_array_equal(observed, known)


line_124 = shapely.LineString((point_1, point_2, point_4))
line_1234 = shapely.LineString((point_1, point_2, point_3, point_4))
line_245 = shapely.LineString((point_2, point_4, point_5))
line_1245 = shapely.LineString((point_1, point_2, point_4, point_5))

known_weld_edges = [
[line_124],
[line_1_2, line_2_4],
[line_1_2, line_2_4],
[line_124],
[line_124],
[line_1_2, line_3_4],
[line_1_2, line_3_4],
[line_1_2, line_3_4],
[line_1_2, line_3_4],
[line_1_2, line_3_4],
[line_1234],
[line_1_2, line_234],
[line_1_2, line_234],
[line_1234],
[line_1234],
[line_1245],
[line_245, line_1_2],
[line_245, line_1_2],
[line_1245],
[line_1245],
]

cases_types_weld_edges = copy.deepcopy(cases_types_get_components)


cases_weld_edges = [
(*arg12, arg3)
for arg12, arg3 in list(zip(cases_types_weld_edges, known_weld_edges, strict=True))
]

case_ids_weld_edges = copy.deepcopy(case_ids_get_components)


@pytest.mark.parametrize(
"edgelines,ignore,known",
cases_weld_edges,
ids=case_ids_weld_edges,
)
def test_weld_edges(edgelines, ignore, known):
observed = sgeop.nodes.weld_edges(edgelines, ignore=ignore)
numpy.testing.assert_array_equal(observed, known)

0 comments on commit 35bd6a0

Please sign in to comment.