BERATools 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. beratools/__init__.py +3 -0
  2. beratools/core/__init__.py +0 -0
  3. beratools/core/algo_centerline.py +476 -0
  4. beratools/core/algo_common.py +489 -0
  5. beratools/core/algo_cost.py +185 -0
  6. beratools/core/algo_dijkstra.py +492 -0
  7. beratools/core/algo_footprint_rel.py +693 -0
  8. beratools/core/algo_line_grouping.py +941 -0
  9. beratools/core/algo_merge_lines.py +255 -0
  10. beratools/core/algo_split_with_lines.py +296 -0
  11. beratools/core/algo_vertex_optimization.py +451 -0
  12. beratools/core/constants.py +56 -0
  13. beratools/core/logger.py +92 -0
  14. beratools/core/tool_base.py +126 -0
  15. beratools/gui/__init__.py +11 -0
  16. beratools/gui/assets/BERALogo.png +0 -0
  17. beratools/gui/assets/beratools.json +471 -0
  18. beratools/gui/assets/closed.gif +0 -0
  19. beratools/gui/assets/closed.png +0 -0
  20. beratools/gui/assets/gui.json +8 -0
  21. beratools/gui/assets/open.gif +0 -0
  22. beratools/gui/assets/open.png +0 -0
  23. beratools/gui/assets/tool.gif +0 -0
  24. beratools/gui/assets/tool.png +0 -0
  25. beratools/gui/bt_data.py +485 -0
  26. beratools/gui/bt_gui_main.py +700 -0
  27. beratools/gui/main.py +27 -0
  28. beratools/gui/tool_widgets.py +730 -0
  29. beratools/tools/__init__.py +7 -0
  30. beratools/tools/canopy_threshold_relative.py +769 -0
  31. beratools/tools/centerline.py +127 -0
  32. beratools/tools/check_seed_line.py +48 -0
  33. beratools/tools/common.py +622 -0
  34. beratools/tools/line_footprint_absolute.py +203 -0
  35. beratools/tools/line_footprint_fixed.py +480 -0
  36. beratools/tools/line_footprint_functions.py +884 -0
  37. beratools/tools/line_footprint_relative.py +75 -0
  38. beratools/tools/tool_template.py +72 -0
  39. beratools/tools/vertex_optimization.py +57 -0
  40. beratools-0.1.0.dist-info/METADATA +134 -0
  41. beratools-0.1.0.dist-info/RECORD +44 -0
  42. beratools-0.1.0.dist-info/WHEEL +4 -0
  43. beratools-0.1.0.dist-info/entry_points.txt +2 -0
  44. beratools-0.1.0.dist-info/licenses/LICENSE +22 -0
@@ -0,0 +1,127 @@
1
+ """
2
+ Copyright (C) 2025 Applied Geospatial Research Group.
3
+
4
+ This script is licensed under the GNU General Public License v3.0.
5
+ See <https://gnu.org/licenses/gpl-3.0> for full license details.
6
+
7
+ Author: Richard Zeng
8
+
9
+ Description:
10
+ This script is part of the BERA Tools.
11
+ Webpage: https://github.com/appliedgrg/beratools
12
+
13
+ The purpose of this script is to provide main interface for centerline tool.
14
+ """
15
+
16
+ import logging
17
+ import time
18
+ from pathlib import Path
19
+
20
+ import pandas as pd
21
+
22
+ import beratools.core.algo_centerline as algo_centerline
23
+ import beratools.core.algo_common as algo_common
24
+ import beratools.core.constants as bt_const
25
+ import beratools.tools.common as bt_common
26
+ from beratools.core.logger import Logger
27
+ from beratools.core.tool_base import execute_multiprocessing
28
+
29
+ log = Logger("centerline", file_level=logging.INFO)
30
+ logger = log.get_logger()
31
+ print = log.print
32
+
33
+
34
+ def generate_line_class_list(in_vector, in_raster, line_radius, layer=None, proc_segments=True) -> list:
35
+ line_classes = []
36
+ line_list = algo_common.prepare_lines_gdf(in_vector, layer, proc_segments)
37
+
38
+ for item in line_list:
39
+ line_classes.append(algo_centerline.SeedLine(item, in_raster, proc_segments, line_radius))
40
+
41
+ return line_classes
42
+
43
+
44
+ def process_single_line_class(seed_line):
45
+ seed_line.compute()
46
+ return seed_line
47
+
48
+
49
+ def centerline(
50
+ in_line,
51
+ in_raster,
52
+ line_radius,
53
+ proc_segments,
54
+ out_line,
55
+ processes,
56
+ verbose,
57
+ in_layer=None,
58
+ out_layer=None,
59
+ parallel_mode=bt_const.ParallelMode.MULTIPROCESSING,
60
+ ):
61
+ if not bt_common.compare_crs(bt_common.vector_crs(in_line), bt_common.raster_crs(in_raster)):
62
+ print("Line and CHM have different spatial references, please check.")
63
+ return
64
+
65
+ line_class_list = generate_line_class_list(
66
+ in_line,
67
+ in_raster,
68
+ line_radius=float(line_radius),
69
+ layer=in_layer,
70
+ proc_segments=proc_segments,
71
+ )
72
+
73
+ print("{} lines to be processed.".format(len(line_class_list)))
74
+
75
+ lc_path_list = []
76
+ centerline_list = []
77
+ corridor_poly_list = []
78
+ result = execute_multiprocessing(
79
+ process_single_line_class,
80
+ line_class_list,
81
+ "Centerline",
82
+ processes,
83
+ verbose=verbose,
84
+ mode=parallel_mode,
85
+ )
86
+ if not result:
87
+ print("No centerlines found.")
88
+ return
89
+
90
+ for item in result:
91
+ lc_path_list.append(item.lc_path)
92
+ centerline_list.append(item.centerline)
93
+ corridor_poly_list.append(item.corridor_poly_gpd)
94
+
95
+ # Concatenate the lists of GeoDataFrames into single GeoDataFrames
96
+ if len(lc_path_list) == 0 or len(centerline_list) == 0 or len(corridor_poly_list) == 0:
97
+ print("No centerline generated.")
98
+ return 1
99
+
100
+ lc_path_list = pd.concat(lc_path_list, ignore_index=True)
101
+ centerline_list = pd.concat(centerline_list, ignore_index=True)
102
+ corridor_polys = pd.concat(corridor_poly_list, ignore_index=True)
103
+
104
+ # Save the concatenated GeoDataFrames to the shapefile/gpkg
105
+ centerline_list.to_file(out_line, layer=out_layer)
106
+
107
+ # Check if the output file is a shapefile
108
+ out_line_path = Path(out_line)
109
+
110
+ if out_line_path.suffix == ".shp":
111
+ # Generate the new file name for the GeoPackage with '_aux' appended
112
+ aux_file = out_line_path.with_name(out_line_path.stem + "_aux.gpkg")
113
+ print(f"Saved auxiliary data to: {aux_file}")
114
+ else:
115
+ aux_file = out_line # continue using out_line (gpkg)
116
+
117
+ # Save lc_path_list and corridor_polys to the new GeoPackage with '_aux' suffix
118
+ lc_path_list.to_file(aux_file, layer="least_cost_path")
119
+ corridor_polys.to_file(aux_file, layer="corridor_polygon")
120
+
121
+
122
+ # TODO: fix geometries when job done
123
+ if __name__ == "__main__":
124
+ in_args, in_verbose = bt_common.check_arguments()
125
+ start_time = time.time()
126
+ centerline(**in_args.input, processes=int(in_args.processes), verbose=in_verbose)
127
+ print("Elapsed time: {}".format(time.time() - start_time))
@@ -0,0 +1,48 @@
1
+ """
2
+ Copyright (C) 2025 Applied Geospatial Research Group.
3
+
4
+ This script is licensed under the GNU General Public License v3.0.
5
+ See <https://gnu.org/licenses/gpl-3.0> for full license details.
6
+
7
+ Author: Richard Zeng
8
+
9
+ Description:
10
+ This script is part of the BERA Tools.
11
+ Webpage: https://github.com/appliedgrg/beratools
12
+
13
+ The purpose of this script is to provide main interface for line grouping tool.
14
+ """
15
+
16
+ import logging
17
+ import time
18
+
19
+ import geopandas as gpd
20
+
21
+ import beratools.tools.common as bt_common
22
+ from beratools.core.algo_line_grouping import LineGrouping
23
+ from beratools.core.logger import Logger
24
+ from beratools.tools.common import qc_merge_multilinestring, qc_split_lines_at_intersections
25
+
26
+
27
+ def check_seed_line(
28
+ in_line, out_line, verbose, processes=-1, in_layer=None, out_layer=None, use_angle_grouping=True
29
+ ):
30
+ print("check_seed_line started")
31
+ in_line_gdf = gpd.read_file(in_line, layer=in_layer)
32
+ in_line_gdf = qc_merge_multilinestring(in_line_gdf)
33
+ in_line_gdf = qc_split_lines_at_intersections(in_line_gdf)
34
+ lg = LineGrouping(in_line_gdf, use_angle_grouping=use_angle_grouping)
35
+ lg.run_grouping()
36
+ lg.lines.to_file(out_line, layer=out_layer)
37
+
38
+
39
+ log = Logger("check_seed_line", file_level=logging.INFO)
40
+ logger = log.get_logger()
41
+ print = log.print
42
+
43
+ if __name__ == "__main__":
44
+ in_args, in_verbose = bt_common.check_arguments()
45
+ start_time = time.time()
46
+ check_seed_line(**in_args.input, processes=int(in_args.processes), verbose=in_verbose)
47
+
48
+ print("Elapsed time: {}".format(time.time() - start_time))