Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dedicated minimal tests -- nodes.weld_edges() #58

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)