@@ -26,21 +26,30 @@ class GeneralizeFences(BaseAlgorithm):
2626 "masts".
2727
2828 Output contains the generalized line fences.
29+
30+ The algorithm does the following steps:
31+ - Merges line segments
32+ - Adds helper lines to close small gaps between lines
33+ - Removes short lines within large enough enclosed areas
34+ - Removes surrounding lines of small enough enclosed areas
35+ - Removes close enough lines surrounding a mast
36+ - Removes all short lines
37+ - Simplifies all lines
2938 """
3039
31- closing_fence_area_threshold : float
40+ closing_fence_area_threshold : float = 2000.0
3241 """Minimum area for a fence-enclosed region."""
33- closing_fence_area_with_mast_threshold : float
42+ closing_fence_area_with_mast_threshold : float = 8000.0
3443 """Minimum area for a fence-enclosed region containing a mast."""
35- fence_length_threshold : float
44+ fence_length_threshold : float = 80.0
3645 """Minimum length for a fence line."""
37- fence_length_threshold_in_closed_area : float
46+ fence_length_threshold_in_closed_area : float = 300.0
3847 """Minimum length for a fence line within a closed area."""
39- simplification_tolerance : float
48+ simplification_tolerance : float = 4.0
4049 """Tolerance used for geometry simplification."""
41- gap_threshold : float
50+ gap_threshold : float = 25.0
4251 """Maximum gap between two fence lines to be connected with a helper line."""
43- attribute_for_line_merge : str
52+ attribute_for_line_merge : str = "kohdeluokka"
4453 """Name of the attribute to determine which line features can be merged."""
4554
4655 @override
@@ -67,7 +76,8 @@ def _execute(
6776 GeoDataFrame with key "masts" in `reference_data` contains
6877 non-point geometries.
6978 KeyError: If `reference_data` does not contain data with key
70- "masts".
79+ "masts" or input data does not have specified
80+ `attribute_for_line_merge`.
7181
7282 """
7383 if not check_gdf_geometry_type (data , ["LineString" ]):
@@ -82,6 +92,12 @@ def _execute(
8292 if not check_gdf_geometry_type (reference_data ["masts" ], ["Point" ]):
8393 msg = "Masts data should be a Point GeoDataFrame."
8494 raise GeometryTypeError (msg )
95+ if self .attribute_for_line_merge not in data .columns :
96+ msg = (
97+ "Specified `attribute_for_line_merge` "
98+ + f"({ self .attribute_for_line_merge } ) not found in input GeoDataFrame."
99+ )
100+ raise KeyError (msg )
85101
86102 result_gdf = data .copy ()
87103
0 commit comments