|
6 | 6 | # LICENSE file in the root directory of this source tree. |
7 | 7 |
|
8 | 8 | import geopandas as gpd |
| 9 | +import pytest |
9 | 10 | from pandas.testing import assert_frame_equal |
10 | | -from shapely import Point, equals_exact |
| 11 | +from shapely import LineString, Point, equals_exact |
11 | 12 |
|
12 | 13 | from geogenalg.application.generalize_points import GeneralizePoints |
| 14 | +from geogenalg.core.exceptions import GeometryTypeError |
13 | 15 |
|
14 | 16 |
|
15 | 17 | def test_generalize_points() -> None: |
@@ -91,3 +93,28 @@ def test_generalize_points() -> None: |
91 | 93 | result_attrs = result_gdf.drop(columns="geometry").reset_index(drop=True) |
92 | 94 | expected_attrs = expected_gdf.drop(columns="geometry").reset_index(drop=True) |
93 | 95 | assert_frame_equal(result_attrs, expected_attrs) |
| 96 | + |
| 97 | + |
| 98 | +def test_generalize_points_invalid_geometry_type(): |
| 99 | + algorithm = GeneralizePoints( |
| 100 | + reduce_threshold=0.5, |
| 101 | + displace_threshold=3, |
| 102 | + displace_points_iterations=10, |
| 103 | + unique_key_column="id", |
| 104 | + cluster_members_column="cluster_members", |
| 105 | + ) |
| 106 | + |
| 107 | + input_data = gpd.GeoDataFrame( |
| 108 | + { |
| 109 | + "id": [1, 2], |
| 110 | + }, |
| 111 | + geometry=[ |
| 112 | + LineString([Point(0.5, 0.5), Point(1.0, 1.0)]), |
| 113 | + LineString([Point(2.0, 2.0), Point(2.5, 2.5)]), |
| 114 | + ], |
| 115 | + ) |
| 116 | + |
| 117 | + with pytest.raises( |
| 118 | + GeometryTypeError, match=r"GeneralizePoints works only with Point geometries." |
| 119 | + ): |
| 120 | + algorithm.execute(input_data, {}) |
0 commit comments