Python API Reference
This page documents the main Python modules in BERA Tools using mkdocstrings.
Core Algorithms
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
This file is intended to be hosting algorithms and utility functions/classes for centerline tool.
CenterlineParams
Bases: float, Enum
Parameters for centerline generation.
These parameters are used to control the behavior of centerline generation and should be adjusted based on the specific requirements of the application.
Source code in beratools/core/algo_centerline.py
37 38 39 40 41 42 43 44 45 46 47 48 49 | |
CenterlineStatus
Bases: IntEnum
Status of centerline generation.
This enum is used to indicate the status of centerline generation. It can be used to track the success or failure of the centerline generation process.
Source code in beratools/core/algo_centerline.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
SeedLine
Class to store seed line and least cost path.
Source code in beratools/core/algo_centerline.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
centerline_is_valid(centerline, input_line)
Check if centerline is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centerline
|
_type_
|
description |
required |
input_line
|
LineString
|
Seed line or least cost path. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if line is valid |
Source code in beratools/core/algo_centerline.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
find_centerline(poly, input_line)
Find centerline from polygon and input line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poly
|
sh_geom.Polygon |
required | |
input_line
|
LineString
|
Least cost path or seed line |
required |
Returns: centerline (sh_geom.LineString): Centerline status (CenterlineStatus): Status of centerline generation
Source code in beratools/core/algo_centerline.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
process_single_centerline(row_and_path)
Find centerline.
Args: row_and_path (list of row (gdf and lc_path)): and least cost path first is GeoPandas row, second is input line, (least cost path)
Returns: row: GeoPandas row with centerline
Source code in beratools/core/algo_centerline.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
regenerate_centerline(poly, input_line)
Regenerates centerline when initial poly is not valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_line
|
LineString
|
Seed line or least cost path. |
required |
Returns:
| Type | Description |
|---|---|
|
sh_geom.MultiLineString |
Source code in beratools/core/algo_centerline.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
The purpose of this script is to provide common algorithms and utility functions/classes.
clean_geometries(gdf)
Remove rows with invalid, None, or empty geometries from the GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
The GeoDataFrame to clean. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
The cleaned GeoDataFrame with valid, non-null, |
|
|
and non-empty geometries. |
Source code in beratools/core/algo_common.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
clean_line_geometries(line_gdf)
Clean line geometries in the GeoDataFrame.
Source code in beratools/core/algo_common.py
120 121 122 123 124 125 126 127 128 129 130 | |
corridor_raster(raster_clip, out_meta, source, destination, cell_size, corridor_threshold)
Calculate corridor raster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_clip
|
raster
|
|
required |
out_meta
|
raster file meta |
required | |
source
|
list of point tuple(s)
|
start point in row/col |
required |
destination
|
list of point tuple(s)
|
end point in row/col |
required |
cell_size
|
tuple
|
(cell_size_x, cell_size_y) |
required |
Returns: corridor raster
Source code in beratools/core/algo_common.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
generate_perpendicular_line_precise(points, offset=20)
Generate a perpendicular line to the input line at the given point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
list[Point]
|
The points where to generate the perpendicular lines. |
required |
offset
|
float
|
The length of the perpendicular line. |
20
|
Returns:
| Type | Description |
|---|---|
|
shapely.geometry.LineString: The generated perpendicular line. |
Source code in beratools/core/algo_common.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
get_angle(line, vertex_index)
Calculate the angle of the first or last segment.
TODO: use np.arctan2 instead of np.arctan
Args: line: LineString end_index: 0 or -1 of the line vertices. Consider the multipart.
Source code in beratools/core/algo_common.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
has_multilinestring(gdf)
Check if any geometry is a MultiLineString.
Source code in beratools/core/algo_common.py
94 95 96 97 98 | |
intersection_of_lines(line_1, line_2)
Only LINESTRING is dealt with for now.
Args: line_1 : line_2 :
Returns: sh_geom.Point: intersection point
Source code in beratools/core/algo_common.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
prepare_lines_gdf(file_path, layer=None, proc_segments=True)
Split lines at vertices or return original rows.
It handles for MultiLineString.
Source code in beratools/core/algo_common.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
process_single_item(cls_obj)
Process a class object for universal multiprocessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls_obj
|
Class object to be processed |
required |
Returns:
| Name | Type | Description |
|---|---|---|
cls_obj |
Class object after processing |
Source code in beratools/core/algo_common.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
read_geospatial_file(file_path, layer=None)
Read a geospatial file, clean the geometries and return a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The path to the geospatial file (e.g., .shp, .gpkg). |
required |
layer
|
str
|
The specific layer to read if the file is |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
The cleaned GeoDataFrame containing the data from the file |
|
|
with valid geometries only. |
||
None |
If there is an error reading the file or layer. |
Source code in beratools/core/algo_common.py
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 | |
save_raster_to_file(in_raster_mem, in_meta, out_raster_file)
Save raster matrix in memory to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_raster_mem
|
numpy raster |
required | |
in_meta
|
input meta |
required | |
out_raster_file
|
output raster file |
required |
Source code in beratools/core/algo_common.py
332 333 334 335 336 337 338 339 340 341 342 343 | |
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
This file hosts cost raster related functions.
circle_kernel_refactor(size, radius)
Create a circular kernel using Scipy.
Args: size : kernel size radius : radius of the circle
Returns: kernel (ndarray): A circular kernel.
Examples: kernel_scipy = create_circle_kernel_scipy(17, 8) will replicate xarray-spatial kernel cell_x = 0.3 cell_y = 0.3 tree_radius = 2.5 convolution.circle_kernel(cell_x, cell_y, tree_radius)
Source code in beratools/core/algo_cost.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
cost_norm_dist_transform(canopy_ndarray, max_line_dist, sampling)
Compute a distance-based cost map based on the proximity of valid data points.
Source code in beratools/core/algo_cost.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
cost_raster(in_raster, meta, tree_radius=2.5, canopy_ht_threshold=2.5, max_line_dist=2.5, canopy_avoid=0.4, cost_raster_exponent=1.5)
General version of cost_raster.
To be merged later: variables and consistent nodata solution
Source code in beratools/core/algo_cost.py
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 | |
dyn_np_cc_map(in_chm, canopy_ht_threshold)
Create a new canopy raster.
MaskedArray based on the threshold comparison of in_chm (canopy height model) with canopy_ht_threshold. It assigns 1.0 where the condition is True (canopy) and 0.0 where the condition is False (non-canopy).
Source code in beratools/core/algo_cost.py
67 68 69 70 71 72 73 74 75 76 77 | |
Least Cost Path Algorithm.
This algorithm is adapted from the QGIS plugin: Find the least cost path with given cost raster and points Original author: FlowMap Group@SESS.PKU Source code repository: https://github.com/Gooong/LeastCostPath
Copyright (C) 2023 by AppliedGRG Author: Richard Zeng Date: 2023-03-01
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
MinCostPathHelper
Helper class for the cost matrix.
Source code in beratools/core/algo_dijkstra.py
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 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
dijkstra_np(start_tuple, end_tuple, matrix)
Dijkstra's algorithm for finding the shortest path between two nodes in a graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_node
|
list
|
[row,col] coordinates of the initial node |
required |
end_node
|
list
|
[row,col] coordinates of the desired node |
required |
matrix
|
array 2d
|
numpy array that contains matrix as 1s and free space as 0s |
required |
Returns:
| Type | Description |
|---|---|
|
list[list]: list of list of nodes that form the shortest path |
Source code in beratools/core/algo_dijkstra.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
valid_node(node, size_of_grid)
Check if node is within the grid boundaries.
Source code in beratools/core/algo_dijkstra.py
268 269 270 271 272 273 274 | |
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng, Maverick Fong
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
The purpose of this script is to provide main interface for canopy footprint tool. The tool is used to generate the footprint of a line based on relative threshold.
BufferRing
Buffer ring class.
Source code in beratools/core/algo_footprint_rel.py
110 111 112 113 114 115 116 117 | |
FootprintCanopy
Relative canopy footprint class.
Source code in beratools/core/algo_footprint_rel.py
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
LineInfo
Class to store line information.
Source code in beratools/core/algo_footprint_rel.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
multi_ring_buffer(df, nrings, ringdist)
Buffers an input DataFrames geometry nring (number of rings) times.
Compute with a distance between rings of ringdist and returns a list of non overlapping buffers
Source code in beratools/core/algo_footprint_rel.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
Side
Bases: Enum
Constants for left and right side.
Source code in beratools/core/algo_footprint_rel.py
38 39 40 41 42 | |
line_footprint_rel(in_line, in_chm, out_footprint, processes, verbose=True, in_layer=None, out_layer=None, max_ln_width=32, tree_radius=1.5, max_line_dist=1.5, canopy_avoidance=0.0, exponent=1.0, canopy_thresh_percentage=50, parallel_mode=bt_const.ParallelMode.MULTIPROCESSING)
Safe version of relative canopy footprint tool.
Source code in beratools/core/algo_footprint_rel.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng, Maverick Fong
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
This file hosts code to deal with line grouping and merging, cleanups.
LineGrouping
Class to group lines and merge them.
Source code in beratools/core/algo_line_grouping.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 | |
check_geom_validity()
Check MultiLineString and MultiPolygon in line and polygon dataframe.
Save to separate layers for user to double check
Source code in beratools/core/algo_line_grouping.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | |
run_regrouping()
Run this when new lines are added to grouped file.
Some new lines has empty group attributes
Source code in beratools/core/algo_line_grouping.py
797 798 799 800 801 802 803 | |
update_line_in_vertex_node(line_id, line)
Update line in VertexNode after trimming.
Source code in beratools/core/algo_line_grouping.py
715 716 717 718 719 720 | |
PolygonTrimming
dataclass
Store polygon and line to trim. Primary polygon is used to trim both.
Source code in beratools/core/algo_line_grouping.py
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | |
SingleLine
dataclass
Class to store line and its simplified line.
Source code in beratools/core/algo_line_grouping.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
VertexClass
Bases: IntEnum
Enum class for vertex class.
Source code in beratools/core/algo_line_grouping.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
VertexNode
Class to store vertex and lines connected to it.
Source code in beratools/core/algo_line_grouping.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
add_line(line_class)
Add line when creating or merging other VertexNode.
Source code in beratools/core/algo_line_grouping.py
159 160 161 162 | |
all_has_valid_group_attr()
If all values in group list are valid value, return True.
Source code in beratools/core/algo_line_grouping.py
530 531 532 533 534 535 536 537 | |
get_transect_for_primary()
Get a transect line from two primary connected lines.
This method calculates a transect line that is perpendicular to the line segment formed by the next vertex neighbors of these two lines and the current vertex.
Return
A transect line object if the conditions are met, otherwise None.
Source code in beratools/core/algo_line_grouping.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
get_transect_for_primary_second()
Get a transect line from the second primary connected line.
For the second primary line, this method retrieves the neighbor point from two lines in the second connectivity group, creates a reference line through the vertex by mirroring the neighbor point about the vertex, and then generates a parallel line centered at the vertex.
Returns:
| Type | Description |
|---|---|
|
A LineString representing the transect if available, otherwise None. |
Source code in beratools/core/algo_line_grouping.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
group_line_by_angle()
Generate connectivity of all lines.
Source code in beratools/core/algo_line_grouping.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
merge(vertex)
Merge other VertexNode if they have same vertex coords.
Source code in beratools/core/algo_line_grouping.py
186 187 188 | |
parallel_line_centered(p1, p2, center, length)
staticmethod
Generate a parallel line.
Source code in beratools/core/algo_line_grouping.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
set_vertex(line, vertex_index)
Set vertex coordinates.
Source code in beratools/core/algo_line_grouping.py
155 156 157 | |
trim_end_all(polys)
Trim all unconnected lines in the vertex.
Args: polys: list of polygons returned by sindex.query
Source code in beratools/core/algo_line_grouping.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
trim_intersection(polys, merge_group=True)
Trim intersection of lines and polygons.
TODO: there are polygons of 0 zero.
Source code in beratools/core/algo_line_grouping.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
trim_primary_end(polys)
Trim first primary line in the vertex.
Args: polys: list of polygons returned by sindex.query
Source code in beratools/core/algo_line_grouping.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
get_angle(line, end_index)
Calculate the angle of the first or last segment.
Args: line: sh_geom.LineString end_index: 0 or -1 of the line vertices. Consider the multipart.
Source code in beratools/core/algo_line_grouping.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
points_in_line(line)
Get point list of line.
Source code in beratools/core/algo_line_grouping.py
70 71 72 73 74 75 76 77 78 79 80 81 | |
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
This file is intended to be hosting algorithms and utility functions/classes for merging lines.
MergeLines
Merge line segments in MultiLineString.
Source code in beratools/core/algo_merge_lines.py
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 92 93 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
Split lines at intersections using a class-based approach.
LineSplitter
Split lines at intersections.
Source code in beratools/core/algo_split_with_lines.py
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 92 93 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
__init__(line_gdf)
Initialize the LineSplitter with the input GeoPackage and layer name.
Args: input_gpkg (str): Path to the input GeoPackage file. layer_name (str): Name of the layer to read from the GeoPackage.
Source code in beratools/core/algo_split_with_lines.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
cut_line_by_points(line, points)
Cuts a LineString into segments based on the given points.
Args: line: A shapely LineString to be cut. points: A list of Point objects where the LineString needs to be cut.
Return: A list of LineString segments after the cuts.
Source code in beratools/core/algo_split_with_lines.py
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 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
find_intersections()
Find intersections between lines in the GeoDataFrame.
Return: List of Point geometries where the lines intersect.
Source code in beratools/core/algo_split_with_lines.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
process(intersection_gdf=None)
Find intersection points, split lines at intersections.
Args: intersection_gdf: external GeoDataFrame with intersection points.
Source code in beratools/core/algo_split_with_lines.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
save_to_geopackage(input_gpkg, line_layer='split_lines', intersection_layer=None, invalid_layer=None)
Save the split lines and intersection points to the GeoPackage.
Args: line_layer: split lines layer name in the GeoPackage. intersection_layer: layer name for intersection points in the GeoPackage.
Source code in beratools/core/algo_split_with_lines.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
split_lines_at_intersections()
Split lines at the given intersection points.
Args: intersection_points: List of Point geometries where the lines should be split.
Returns: A GeoDataFrame with the split lines.
Source code in beratools/core/algo_split_with_lines.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
The purpose of this script is to move line vertices to the right seismic line courses for improved alignment and analysis in geospatial data processing.
VertexGrouping
A class used to group vertices and perform vertex optimization.
Source code in beratools/core/algo_vertex_optimization.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
create_vertex_group(line_obj)
Create a new vertex group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_obj
|
_SingleLine |
required |
Source code in beratools/core/algo_vertex_optimization.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
Constants
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
The purpose of this script is to provide common constants.
CenterlineFlags
Bases: Flag
Flags for the centerline algorithm.
Source code in beratools/core/constants.py
36 37 38 39 40 41 | |
ParallelMode
Bases: IntEnum
Defines the parallel mode for the algorithms.
Source code in beratools/core/constants.py
44 45 46 47 48 49 50 51 52 | |
Logger
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
The purpose of this script is to provide logger functions.
Logger
Bases: object
Logger class to handle logging in the BERA Tools application.
This class sets up a logger that outputs to both the console and a file. It allows for different logging levels for console and file outputs. It also provides a method to print messages directly to the logger.
Source code in beratools/core/logger.py
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 92 | |
print(msg, flush=True)
Re-define print in logging.
Args: msg : flush :
Source code in beratools/core/logger.py
56 57 58 59 60 61 62 63 64 65 66 67 68 | |
NoParsingFilter
Bases: Filter
Filter to exclude log messages that start with "parsing".
This is useful to avoid cluttering the log with parsing-related messages.
Source code in beratools/core/logger.py
25 26 27 28 29 30 31 32 33 | |
Tool Base
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Richard Zeng
Description
This script is part of the BERA Tools. Webpage: https://github.com/appliedgrg/beratools
The purpose of this script is to provide fundamental utilities for tools.
ToolBase
Bases: object
Base class for tools.
Source code in beratools/core/tool_base.py
36 37 38 39 40 41 42 43 | |