Skip to content

Commit

Permalink
fix(gridintersect): add multilinestring tests (#1924)
Browse files Browse the repository at this point in the history
- tests for example in #1922
  • Loading branch information
dbrakenhoff authored and wpbonelli committed Aug 25, 2023
1 parent 22205f4 commit 672d6be
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions autotest/test_gridintersect.py
Expand Up @@ -425,6 +425,22 @@ def test_rect_grid_multilinestring_in_one_cell():
assert result.cellids[0] == (1, 0)


@requires_pkg("shapely")
def test_rect_grid_multilinestring_in_multiple_cells():
gr = get_rect_grid()
ix = GridIntersect(gr, method="structured")
result = ix.intersect(
MultiLineString(
[
LineString([(20.0, 0.0), (7.5, 12.0), (2.5, 7.0), (0.0, 4.5)]),
LineString([(5.0, 19.0), (2.5, 7.0)]),
]
)
)
assert len(result) == 3
assert np.allclose(sum(result.lengths), 40.19197584109293)


@requires_pkg("shapely")
def test_rect_grid_linestring_in_and_out_of_cell():
gr = get_rect_grid()
Expand Down Expand Up @@ -537,6 +553,23 @@ def test_rect_grid_multilinestring_in_one_cell_shapely(rtree):
assert result.cellids[0] == (1, 0)


@requires_pkg("shapely")
@rtree_toggle
def test_rect_grid_multilinestring_in_multiple_cells_shapely(rtree):
gr = get_rect_grid()
ix = GridIntersect(gr, method="vertex", rtree=rtree)
result = ix.intersect(
MultiLineString(
[
LineString([(20.0, 0.0), (7.5, 12.0), (2.5, 7.0), (0.0, 4.5)]),
LineString([(5.0, 19.0), (2.5, 7.0)]),
]
)
)
assert len(result) == 3
assert np.allclose(sum(result.lengths), 40.19197584109293)


@requires_pkg("shapely")
@rtree_toggle
def test_rect_grid_linestring_in_and_out_of_cell_shapely(rtree):
Expand Down Expand Up @@ -655,6 +688,25 @@ def test_tri_grid_multilinestring_in_one_cell(rtree):
assert result.cellids[0] == 4


@requires_pkg("shapely")
@rtree_toggle
def test_tri_grid_multilinestring_in_multiple_cells(rtree):
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr, rtree=rtree)
result = ix.intersect(
MultiLineString(
[
LineString([(20.0, 0.0), (7.5, 12.0), (2.5, 7.0), (0.0, 4.5)]),
LineString([(5.0, 19.0), (2.5, 7.0)]),
]
)
)
assert len(result) == 5
assert np.allclose(sum(result.lengths), 40.19197584109293)


@requires_pkg("shapely")
@rtree_toggle
def test_tri_grid_linestrings_on_boundaries_return_all_ix(rtree):
Expand Down

0 comments on commit 672d6be

Please sign in to comment.