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.
- beratools/__init__.py +3 -0
- beratools/core/__init__.py +0 -0
- beratools/core/algo_centerline.py +476 -0
- beratools/core/algo_common.py +489 -0
- beratools/core/algo_cost.py +185 -0
- beratools/core/algo_dijkstra.py +492 -0
- beratools/core/algo_footprint_rel.py +693 -0
- beratools/core/algo_line_grouping.py +941 -0
- beratools/core/algo_merge_lines.py +255 -0
- beratools/core/algo_split_with_lines.py +296 -0
- beratools/core/algo_vertex_optimization.py +451 -0
- beratools/core/constants.py +56 -0
- beratools/core/logger.py +92 -0
- beratools/core/tool_base.py +126 -0
- beratools/gui/__init__.py +11 -0
- beratools/gui/assets/BERALogo.png +0 -0
- beratools/gui/assets/beratools.json +471 -0
- beratools/gui/assets/closed.gif +0 -0
- beratools/gui/assets/closed.png +0 -0
- beratools/gui/assets/gui.json +8 -0
- beratools/gui/assets/open.gif +0 -0
- beratools/gui/assets/open.png +0 -0
- beratools/gui/assets/tool.gif +0 -0
- beratools/gui/assets/tool.png +0 -0
- beratools/gui/bt_data.py +485 -0
- beratools/gui/bt_gui_main.py +700 -0
- beratools/gui/main.py +27 -0
- beratools/gui/tool_widgets.py +730 -0
- beratools/tools/__init__.py +7 -0
- beratools/tools/canopy_threshold_relative.py +769 -0
- beratools/tools/centerline.py +127 -0
- beratools/tools/check_seed_line.py +48 -0
- beratools/tools/common.py +622 -0
- beratools/tools/line_footprint_absolute.py +203 -0
- beratools/tools/line_footprint_fixed.py +480 -0
- beratools/tools/line_footprint_functions.py +884 -0
- beratools/tools/line_footprint_relative.py +75 -0
- beratools/tools/tool_template.py +72 -0
- beratools/tools/vertex_optimization.py +57 -0
- beratools-0.1.0.dist-info/METADATA +134 -0
- beratools-0.1.0.dist-info/RECORD +44 -0
- beratools-0.1.0.dist-info/WHEEL +4 -0
- beratools-0.1.0.dist-info/entry_points.txt +2 -0
- 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))
|