1010
1111from geopandas import GeoDataFrame
1212
13- from geogenalg import cluster , displacement
1413from geogenalg .application import BaseAlgorithm
14+ from geogenalg .cluster import reduce_nearby_points_by_clustering
15+ from geogenalg .core .exceptions import GeometryTypeError
16+ from geogenalg .displacement import displace_points
17+ from geogenalg .utility .validation import check_gdf_geometry_type
1518
1619
1720@dataclass (frozen = True )
1821class GeneralizePoints (BaseAlgorithm ):
1922 """Generalizes point features by reducing and displacing them.
2023
24+ Reference data is not used for this algorithm.
25+
26+ Output contains created cluster centroids and single points which
27+ were not turned into centroids. The `cluster_members_column`
28+ attribute lists all points that were clustered or None if the
29+ point is original point from input.
30+
2131 Note:
2232 If more than two points are located close to each other, the exact
2333 `displace_threshold` may not be achieved. Increasing the number of iterations
2434 for displacing points will bring the minimum distances closer to the threshold.
2535
36+ The algorithm does the following steps:
37+ - Reduces amount of points by clustering
38+ - Moves points close to each other apart
39+
2640 """
2741
28- reduce_threshold : float
42+ reduce_threshold : float = 10.0
2943 """Distance used for buffering and clustering points."""
30- displace_threshold : float
44+ displace_threshold : float = 70.0
3145 """Minimum allowed distance between points after displacement."""
32- displace_points_iterations : int
46+ displace_points_iterations : int = 10
3347 """The number of times to repeat displacement loop."""
34- unique_key_column : str
48+ unique_key_column : str = "mtk_id"
3549 """Name of the column containing unique identifiers."""
36- cluster_members_column : str
50+ cluster_members_column : str = "cluster_members"
3751 """Name of the column that lists the points included in each cluster."""
3852
3953 @override
40- def execute (
54+ def _execute (
4155 self ,
4256 data : GeoDataFrame ,
4357 reference_data : dict [str , GeoDataFrame ],
@@ -53,14 +67,22 @@ def execute(
5367 -------
5468 A GeoDataFrame containing the generalized points.
5569
70+ Raises:
71+ ------
72+ GeometryTypeError: If `data` contains non-point geometries.
73+
5674 """
57- clustered_points = cluster .reduce_nearby_points_by_clustering (
75+ if not check_gdf_geometry_type (data , ["Point" ]):
76+ msg = "GeneralizePoints works only with Point geometries."
77+ raise GeometryTypeError (msg )
78+
79+ clustered_points = reduce_nearby_points_by_clustering (
5880 data ,
5981 self .reduce_threshold ,
6082 self .unique_key_column ,
6183 self .cluster_members_column ,
6284 )
6385
64- return displacement . displace_points (
86+ return displace_points (
6587 clustered_points , self .displace_threshold , self .displace_points_iterations
6688 )
0 commit comments