BERATools 0.2.0__py3-none-any.whl → 0.2.2__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 +1 -7
- beratools/core/algo_centerline.py +491 -351
- beratools/core/algo_common.py +497 -0
- beratools/core/algo_cost.py +192 -0
- beratools/core/{dijkstra_algorithm.py → algo_dijkstra.py} +503 -460
- beratools/core/algo_footprint_rel.py +577 -0
- beratools/core/algo_line_grouping.py +944 -0
- beratools/core/algo_merge_lines.py +214 -0
- beratools/core/algo_split_with_lines.py +304 -0
- beratools/core/algo_tiler.py +428 -0
- beratools/core/algo_vertex_optimization.py +469 -0
- beratools/core/constants.py +52 -86
- beratools/core/logger.py +76 -85
- beratools/core/tool_base.py +196 -133
- beratools/gui/__init__.py +11 -15
- beratools/gui/{beratools.json → assets/beratools.json} +2185 -2300
- beratools/gui/batch_processing_dlg.py +513 -463
- beratools/gui/bt_data.py +481 -487
- beratools/gui/bt_gui_main.py +710 -691
- beratools/gui/main.py +26 -0
- beratools/gui/map_window.py +162 -146
- beratools/gui/tool_widgets.py +725 -493
- beratools/tools/Beratools_r_script.r +1120 -1120
- beratools/tools/Ht_metrics.py +116 -116
- beratools/tools/__init__.py +7 -7
- beratools/tools/batch_processing.py +136 -132
- beratools/tools/canopy_threshold_relative.py +672 -670
- beratools/tools/canopycostraster.py +222 -222
- beratools/tools/centerline.py +136 -176
- beratools/tools/common.py +857 -885
- beratools/tools/fl_regen_csf.py +428 -428
- beratools/tools/forest_line_attributes.py +408 -408
- beratools/tools/line_footprint_absolute.py +213 -363
- beratools/tools/line_footprint_fixed.py +436 -282
- beratools/tools/line_footprint_functions.py +733 -720
- beratools/tools/line_footprint_relative.py +73 -64
- beratools/tools/line_grouping.py +45 -0
- beratools/tools/ln_relative_metrics.py +615 -615
- beratools/tools/r_cal_lpi_elai.r +24 -24
- beratools/tools/r_generate_pd_focalraster.r +100 -100
- beratools/tools/r_interface.py +79 -79
- beratools/tools/r_point_density.r +8 -8
- beratools/tools/rpy_chm2trees.py +86 -86
- beratools/tools/rpy_dsm_chm_by.py +81 -81
- beratools/tools/rpy_dtm_by.py +63 -63
- beratools/tools/rpy_find_cellsize.py +43 -43
- beratools/tools/rpy_gnd_csf.py +74 -74
- beratools/tools/rpy_hummock_hollow.py +85 -85
- beratools/tools/rpy_hummock_hollow_raster.py +71 -71
- beratools/tools/rpy_las_info.py +51 -51
- beratools/tools/rpy_laz2las.py +40 -40
- beratools/tools/rpy_lpi_elai_lascat.py +466 -466
- beratools/tools/rpy_normalized_lidar_by.py +56 -56
- beratools/tools/rpy_percent_above_dbh.py +80 -80
- beratools/tools/rpy_points2trees.py +88 -88
- beratools/tools/rpy_vegcoverage.py +94 -94
- beratools/tools/tiler.py +48 -206
- beratools/tools/tool_template.py +69 -54
- beratools/tools/vertex_optimization.py +61 -620
- beratools/tools/zonal_threshold.py +144 -144
- beratools-0.2.2.dist-info/METADATA +108 -0
- beratools-0.2.2.dist-info/RECORD +74 -0
- {beratools-0.2.0.dist-info → beratools-0.2.2.dist-info}/WHEEL +1 -1
- {beratools-0.2.0.dist-info → beratools-0.2.2.dist-info}/licenses/LICENSE +22 -22
- beratools/gui/cli.py +0 -18
- beratools/gui/gui.json +0 -8
- beratools/gui_tk/ASCII Banners.txt +0 -248
- beratools/gui_tk/__init__.py +0 -20
- beratools/gui_tk/beratools_main.py +0 -515
- beratools/gui_tk/bt_widgets.py +0 -442
- beratools/gui_tk/cli.py +0 -18
- beratools/gui_tk/img/BERALogo.png +0 -0
- beratools/gui_tk/img/closed.gif +0 -0
- beratools/gui_tk/img/closed.png +0 -0
- beratools/gui_tk/img/open.gif +0 -0
- beratools/gui_tk/img/open.png +0 -0
- beratools/gui_tk/img/tool.gif +0 -0
- beratools/gui_tk/img/tool.png +0 -0
- beratools/gui_tk/main.py +0 -14
- beratools/gui_tk/map_window.py +0 -144
- beratools/gui_tk/runner.py +0 -1481
- beratools/gui_tk/tooltip.py +0 -55
- beratools/third_party/pyqtlet2/__init__.py +0 -9
- beratools/third_party/pyqtlet2/leaflet/__init__.py +0 -26
- beratools/third_party/pyqtlet2/leaflet/control/__init__.py +0 -6
- beratools/third_party/pyqtlet2/leaflet/control/control.py +0 -59
- beratools/third_party/pyqtlet2/leaflet/control/draw.py +0 -52
- beratools/third_party/pyqtlet2/leaflet/control/layers.py +0 -20
- beratools/third_party/pyqtlet2/leaflet/core/Parser.py +0 -24
- beratools/third_party/pyqtlet2/leaflet/core/__init__.py +0 -2
- beratools/third_party/pyqtlet2/leaflet/core/evented.py +0 -180
- beratools/third_party/pyqtlet2/leaflet/layer/__init__.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/featuregroup.py +0 -34
- beratools/third_party/pyqtlet2/leaflet/layer/icon/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/layer/icon/icon.py +0 -30
- beratools/third_party/pyqtlet2/leaflet/layer/imageoverlay.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/layer.py +0 -105
- beratools/third_party/pyqtlet2/leaflet/layer/layergroup.py +0 -45
- beratools/third_party/pyqtlet2/leaflet/layer/marker/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/layer/marker/marker.py +0 -91
- beratools/third_party/pyqtlet2/leaflet/layer/tile/__init__.py +0 -2
- beratools/third_party/pyqtlet2/leaflet/layer/tile/gridlayer.py +0 -4
- beratools/third_party/pyqtlet2/leaflet/layer/tile/tilelayer.py +0 -16
- beratools/third_party/pyqtlet2/leaflet/layer/vector/__init__.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/vector/circle.py +0 -15
- beratools/third_party/pyqtlet2/leaflet/layer/vector/circlemarker.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/vector/path.py +0 -5
- beratools/third_party/pyqtlet2/leaflet/layer/vector/polygon.py +0 -14
- beratools/third_party/pyqtlet2/leaflet/layer/vector/polyline.py +0 -18
- beratools/third_party/pyqtlet2/leaflet/layer/vector/rectangle.py +0 -14
- beratools/third_party/pyqtlet2/leaflet/map/__init__.py +0 -1
- beratools/third_party/pyqtlet2/leaflet/map/map.py +0 -220
- beratools/third_party/pyqtlet2/mapwidget.py +0 -45
- beratools/third_party/pyqtlet2/web/custom.js +0 -43
- beratools/third_party/pyqtlet2/web/map.html +0 -23
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/layers-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/layers.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-icon-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-icon.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/images/marker-shadow.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/leaflet.css +0 -656
- beratools/third_party/pyqtlet2/web/modules/leaflet_193/leaflet.js +0 -6
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.codeclimate.yml +0 -14
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.editorconfig +0 -4
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.gitattributes +0 -22
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/.travis.yml +0 -43
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/LICENSE +0 -20
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/layers-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/layers.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-icon-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-icon.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/marker-shadow.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet-2x.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet.png +0 -0
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/images/spritesheet.svg +0 -156
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/leaflet.draw.css +0 -10
- beratools/third_party/pyqtlet2/web/modules/leaflet_draw_414/leaflet.draw.js +0 -10
- beratools/third_party/pyqtlet2/web/modules/leaflet_rotatedMarker_020/LICENSE +0 -22
- beratools/third_party/pyqtlet2/web/modules/leaflet_rotatedMarker_020/leaflet.rotatedMarker.js +0 -57
- beratools/tools/forest_line_ecosite.py +0 -216
- beratools/tools/lapis_all.py +0 -103
- beratools/tools/least_cost_path_from_chm.py +0 -152
- beratools-0.2.0.dist-info/METADATA +0 -63
- beratools-0.2.0.dist-info/RECORD +0 -142
- /beratools/gui/{img → assets}/BERALogo.png +0 -0
- /beratools/gui/{img → assets}/closed.gif +0 -0
- /beratools/gui/{img → assets}/closed.png +0 -0
- /beratools/{gui_tk → gui/assets}/gui.json +0 -0
- /beratools/gui/{img → assets}/open.gif +0 -0
- /beratools/gui/{img → assets}/open.png +0 -0
- /beratools/gui/{img → assets}/tool.gif +0 -0
- /beratools/gui/{img → assets}/tool.png +0 -0
- {beratools-0.2.0.dist-info → beratools-0.2.2.dist-info}/entry_points.txt +0 -0
beratools/tools/centerline.py
CHANGED
|
@@ -1,176 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if not
|
|
92
|
-
print("
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
for
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
print('{} lines to be processed.'.format(len(all_lines)))
|
|
138
|
-
|
|
139
|
-
lc_path_geoms = []
|
|
140
|
-
feat_props = []
|
|
141
|
-
center_line_geoms = []
|
|
142
|
-
corridor_poly_list = []
|
|
143
|
-
result = execute_multiprocessing(process_single_line, all_lines, 'Centerline',
|
|
144
|
-
processes, 1, verbose=verbose)
|
|
145
|
-
|
|
146
|
-
for item in result:
|
|
147
|
-
center_line = item[0]
|
|
148
|
-
lc_path = item[1]
|
|
149
|
-
prop = item[2]
|
|
150
|
-
corridor_poly = item[3]
|
|
151
|
-
|
|
152
|
-
if lc_path and prop:
|
|
153
|
-
lc_path_geoms.append(lc_path)
|
|
154
|
-
feat_props.append(prop)
|
|
155
|
-
center_line_geoms.append(center_line)
|
|
156
|
-
corridor_poly_list.append(corridor_poly)
|
|
157
|
-
|
|
158
|
-
out_centerline_path = Path(out_line)
|
|
159
|
-
schema['properties']['status'] = 'int'
|
|
160
|
-
save_features_to_shapefile(out_centerline_path.as_posix(), layer_crs, center_line_geoms, feat_props, schema)
|
|
161
|
-
|
|
162
|
-
out_least_cost_path = out_centerline_path.with_stem(out_centerline_path.stem + '_least_cost_path')
|
|
163
|
-
save_features_to_shapefile(out_least_cost_path.as_posix(), layer_crs, lc_path_geoms, feat_props, schema)
|
|
164
|
-
|
|
165
|
-
# save corridor polygons
|
|
166
|
-
corridor_polys = pd.concat(corridor_poly_list)
|
|
167
|
-
out_corridor_poly_path = Path(out_line)
|
|
168
|
-
out_corridor_poly_path = out_corridor_poly_path.with_stem(out_corridor_poly_path.stem + '_corridor_poly')
|
|
169
|
-
corridor_polys.to_file(out_corridor_poly_path.as_posix())
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if __name__ == '__main__':
|
|
173
|
-
in_args, in_verbose = check_arguments()
|
|
174
|
-
start_time = time.time()
|
|
175
|
-
centerline(print, **in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
176
|
-
print('Elapsed time: {}'.format(time.time() - start_time))
|
|
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
|
+
def generate_line_class_list(
|
|
34
|
+
in_vector, in_raster, line_radius, layer=None, proc_segments=True
|
|
35
|
+
) -> list:
|
|
36
|
+
line_classes = []
|
|
37
|
+
line_list = algo_common.prepare_lines_gdf(in_vector, layer, proc_segments)
|
|
38
|
+
|
|
39
|
+
for item in line_list:
|
|
40
|
+
line_classes.append(
|
|
41
|
+
algo_centerline.SeedLine(item, in_raster, proc_segments, line_radius)
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return line_classes
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def process_single_line_class(seed_line):
|
|
48
|
+
seed_line.compute()
|
|
49
|
+
return seed_line
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def centerline(
|
|
53
|
+
in_line,
|
|
54
|
+
in_raster,
|
|
55
|
+
line_radius,
|
|
56
|
+
proc_segments,
|
|
57
|
+
out_line,
|
|
58
|
+
processes,
|
|
59
|
+
verbose,
|
|
60
|
+
in_layer=None,
|
|
61
|
+
out_layer=None,
|
|
62
|
+
parallel_mode=bt_const.ParallelMode.MULTIPROCESSING
|
|
63
|
+
):
|
|
64
|
+
if not bt_common.compare_crs(
|
|
65
|
+
bt_common.vector_crs(in_line), bt_common.raster_crs(in_raster)
|
|
66
|
+
):
|
|
67
|
+
print("Line and CHM have different spatial references, please check.")
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
line_class_list = generate_line_class_list(
|
|
71
|
+
in_line,
|
|
72
|
+
in_raster,
|
|
73
|
+
line_radius=float(line_radius),
|
|
74
|
+
layer=in_layer,
|
|
75
|
+
proc_segments=proc_segments,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
print("{} lines to be processed.".format(len(line_class_list)))
|
|
79
|
+
|
|
80
|
+
lc_path_list = []
|
|
81
|
+
centerline_list = []
|
|
82
|
+
corridor_poly_list = []
|
|
83
|
+
result = execute_multiprocessing(
|
|
84
|
+
process_single_line_class,
|
|
85
|
+
line_class_list,
|
|
86
|
+
"Centerline",
|
|
87
|
+
processes,
|
|
88
|
+
verbose=verbose,
|
|
89
|
+
mode=parallel_mode,
|
|
90
|
+
)
|
|
91
|
+
if not result:
|
|
92
|
+
print("No centerlines found.")
|
|
93
|
+
return
|
|
94
|
+
|
|
95
|
+
for item in result:
|
|
96
|
+
lc_path_list.append(item.lc_path)
|
|
97
|
+
centerline_list.append(item.centerline)
|
|
98
|
+
corridor_poly_list.append(item.corridor_poly_gpd)
|
|
99
|
+
|
|
100
|
+
# Concatenate the lists of GeoDataFrames into single GeoDataFrames
|
|
101
|
+
if (
|
|
102
|
+
len(lc_path_list) == 0
|
|
103
|
+
or len(centerline_list) == 0
|
|
104
|
+
or len(corridor_poly_list) == 0
|
|
105
|
+
):
|
|
106
|
+
print("No centerline generated.")
|
|
107
|
+
return 1
|
|
108
|
+
|
|
109
|
+
lc_path_list = pd.concat(lc_path_list, ignore_index=True)
|
|
110
|
+
centerline_list = pd.concat(centerline_list, ignore_index=True)
|
|
111
|
+
corridor_polys = pd.concat(corridor_poly_list, ignore_index=True)
|
|
112
|
+
|
|
113
|
+
# Save the concatenated GeoDataFrames to the shapefile/gpkg
|
|
114
|
+
centerline_list.to_file(out_line, layer=out_layer)
|
|
115
|
+
|
|
116
|
+
# Check if the output file is a shapefile
|
|
117
|
+
out_line_path = Path(out_line)
|
|
118
|
+
|
|
119
|
+
if out_line_path.suffix == ".shp":
|
|
120
|
+
# Generate the new file name for the GeoPackage with '_aux' appended
|
|
121
|
+
aux_file = out_line_path.with_name(out_line_path.stem + "_aux.gpkg")
|
|
122
|
+
print(f"Saved auxiliary data to: {aux_file}")
|
|
123
|
+
else:
|
|
124
|
+
aux_file = out_line # continue using out_line (gpkg)
|
|
125
|
+
|
|
126
|
+
# Save lc_path_list and corridor_polys to the new GeoPackage with '_aux' suffix
|
|
127
|
+
lc_path_list.to_file(aux_file, layer="least_cost_path")
|
|
128
|
+
corridor_polys.to_file(aux_file, layer="corridor_polygon")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# TODO: fix geometries when job done
|
|
132
|
+
if __name__ == "__main__":
|
|
133
|
+
in_args, in_verbose = bt_common.check_arguments()
|
|
134
|
+
start_time = time.time()
|
|
135
|
+
centerline(**in_args.input, processes=int(in_args.processes), verbose=in_verbose)
|
|
136
|
+
print("Elapsed time: {}".format(time.time() - start_time))
|