Geometry
DHyDAMO Geometry API¶
common
¶
as_linestring_list(linestring: LineString | MultiLineString | list[LineString | MultiLineString]) -> list[LineString]
¶
Returns a list of LineStrings from a given LineString or MultiLineString. Useful for iterating over varying multi of single type geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linestring
|
Union[LineString, MultiLineString]
|
LineString of MultiLineString shapely geometry object |
required |
Returns:
| Type | Description |
|---|---|
list[LineString]
|
List[LineString]: list of shapely geometry LineString objects |
Source code in hydrolib/dhydamo/geometry/common.py
42 43 44 45 46 47 48 49 50 51 52 53 54 | |
as_point_list(point: Point | MultiPoint | list[Point | MultiPoint]) -> list[Point]
¶
Returns a list of Point from a given Point or MultiPoint. Useful for iterating over varying multi of single type geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linestring
|
Union[Point, MultiPoint]
|
Point of MultiPoint shapely geometry object |
required |
Returns:
| Type | Description |
|---|---|
list[Point]
|
List[Point]: list of shapely geometry Point objects |
Source code in hydrolib/dhydamo/geometry/common.py
72 73 74 75 76 77 78 79 80 81 82 83 84 | |
as_polygon_list(polygon: Polygon | MultiPolygon | list[Polygon | MultiPolygon]) -> list[Polygon]
¶
Returns a list of Polygons from a given Polygon or MultiPolygon. Useful for iterating over varying multi of single type geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linestring
|
Union[Polygon, MultiPolygon]
|
Polygon of MultiPolygon shapely geometry object |
required |
Returns:
| Type | Description |
|---|---|
list[Polygon]
|
List[Polygon]: list of shapely geometry Polygon objects |
Source code in hydrolib/dhydamo/geometry/common.py
57 58 59 60 61 62 63 64 65 66 67 68 69 | |
mesh
¶
links1d2d_add_links_1d_to_2d(network: Network, branchids: list[str] = None, within: Polygon | MultiPolygon = None, max_length: float = np.inf) -> None
¶
Function to add 1d2d links to network, by generating them from 1d to 2d. Branchids can be specified for 1d branches that need to be linked. A (Multi)Polygon can be provided were links should be made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network in which the connections are made |
required |
branchids
|
List[str]
|
List of branchid's to connect. If None, all branches are connected. Defaults to None. |
None
|
within
|
Union[Polygon, MultiPolygon]
|
Area within which connections are made. Defaults to None. |
None
|
max_length
|
float
|
Max edge length. Defaults to None. |
inf
|
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
links1d2d_add_links_2d_to_1d_embedded(network: Network, branchids: list[str] = None, within: Polygon | MultiPolygon = None) -> None
¶
Generates links from 2d to 1d, where the 2d mesh intersects the 1d mesh: the 'embedded' links.
To find the intersecting cells in an efficient way, we follow we the next steps. 1) Get the maximum length of a face edge. 2) Buffer the branches with this length. 3) Find all face nodes within this buffered geometry. 4) Check for each of the corresponding faces if it crossed the branches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network in which the links are made. Should contain a 1d and 2d mesh |
required |
branchids
|
List[str]
|
List is branch id's for which the connections are made. Defaults to None. |
None
|
within
|
Union[Polygon, MultiPolygon]
|
Clipping polygon for 2d mesh that is. Defaults to None. |
None
|
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
links1d2d_add_links_2d_to_1d_lateral(network: Network, dist_factor: float | None = 2.0, branchids: list[str] = None, within: Polygon | MultiPolygon = None, max_length: float = np.inf) -> None
¶
Generate 1d2d links from the 2d mesh to the 1d mesh, with a lateral connection. If a link is kept, is determined based on the distance between the face center and the intersection with the 2d mesh exterior. By default, links with an intersection distance larger than 2 times the center to edge distance of the cell, are removed. Note that for a square cell with a direct link out of the cell (without passing any other cells) this max distance is sqrt(2) = 1.414. The default value of 2 provides some flexibility. Note that a link with more than 1 intersection with the 2d mesh boundary is removed anyway.
Furthermore: - Branch ids can be specified to connect only specific branches. - A 'within' polygon can be given to only connect 2d cells within this polygon. - A max link length can be given to limit the link length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network in which the links are made. Should contain a 1d and 2d mesh |
required |
dist_factor
|
Union[float, None]
|
Factor to determine which links are kept (see description above). Defaults to 2.0. |
2.0
|
branchids
|
List[str]
|
List is branch id's for which the conncetions are made. Defaults to None. |
None
|
within
|
Union[Polygon, MultiPolygon]
|
Clipping polygon for 2d mesh that is. Defaults to None. |
None
|
max_length
|
float
|
Max edge length. Defaults to None. |
inf
|
Source code in hydrolib/dhydamo/geometry/mesh.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 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 | |
links1d2d_remove_1d_endpoints(network: Network) -> None
¶
Method to remove 1d2d links from end points of the 1d mesh. The GUI will interpret every endpoint as a boundary conditions, which does not allow a 1d 2d link at the same node. To avoid problems with this, use this method.
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
links1d2d_remove_within(network: Network, within: Polygon | MultiPolygon) -> None
¶
Remove 1d2d links within a given polygon or multipolygon
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The network from which the links are removed |
required |
within
|
Union[Polygon, MultiPolygon]
|
The polygon that indicates which to remove |
required |
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh1d_add_branch_from_linestring(network: Network, linestring: LineString, node_distance: float | int, name: str | None = None, structure_chainage: list[float] | None = None, max_dist_to_struc: float | None = None) -> str
¶
Add branch to 1d mesh, from a LineString geometry. The branch is discretized with the given node distance. The position of a structure can be provided, just like the max distance of a mesh node to a structure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network to which the branch is added |
required |
linestring
|
LineString
|
The geometry of the new branch |
required |
node_distance
|
Union[float, int]
|
Preferred node distance between branch nodes |
required |
name
|
Union[str, None]
|
Name of the branch. If not given, a name is generated. Defaults to None. |
None
|
structure_chainage
|
Union[List[float], None]
|
Positions of structures along the branch. Defaults to Union[float, None]=None. |
None
|
max_dist_to_struc
|
Union[float, None]
|
Max distance of a mesh point to a structure. Defaults to Union[float, None]=None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
name of added branch |
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh1d_add_branches_from_gdf(network: Network, branches: gpd.GeoDataFrame, branch_name_col: str, node_distance: float, max_dist_to_struc: float = None, structures=None) -> None
¶
Function to generate branches from geodataframe
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The network to which the branches are added |
required |
branches
|
GeoDataFrame
|
GeoDataFrame with branches |
required |
branch_name_col
|
str
|
Name of the column in the GeoDataFrame with the branchnames |
required |
node_distance
|
float
|
Preferred 1d mesh distance |
required |
max_dist_to_struc
|
float
|
Maximum distance to structure. Defaults to None. |
None
|
structures
|
GeoDataFrame
|
GeoDataFrame with structures. Must contain a column branchid and chainage. Defaults to None. |
None
|
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh1d_order_numbers_from_attribute(branches: gpd.GeoDataFrame, missing: list, order_attribute: str, network: Network, exceptions: list = []) -> list
¶
mesh1d_order_numbers_from_attribute Method to allocate order numbers to branches based on a common attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branches
|
GeoDataFrame
|
HyDAMO GeoDataFGame containing branches. |
required |
missing
|
list
|
list of branches that have so far not been allocated a cross section. |
required |
order_attribute
|
str
|
description. Attribute of branches based on which order numbers are allocated. |
required |
network
|
Network
|
FM network geometry to which the order numbers should be written |
required |
exceptions
|
list
|
List of branch code that should not be given an order number. Defaults to None. |
[]
|
Returns:
| Name | Type | Description |
|---|---|---|
missing_after_interpolation |
list
|
list of branches that still do not have a cross section |
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh1d_set_branch_order(network: Network, branchids: list, idx: int = None) -> None
¶
Group branch ids so that the cross sections are interpolated along the branch.
Parameters¶
branchids : list List of branches to group idx : int Order number with which to update a branch
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh2d_add_rectilinear(network: Network, polygon: Polygon | MultiPolygon, dx: float, dy: float, deletemeshoption: mk.DeleteMeshOption = mk.DeleteMeshOption.INSIDE_NOT_INTERSECTED) -> None
¶
Add 2d rectilinear mesh to network. A new network is created, clipped, and merged with the existing network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network object to which the mesh is added |
required |
polygon
|
Union[Polygon, MultiPolygon]
|
Geometry within which the mesh is generated |
required |
dx
|
float
|
Horizontal mesh spacing |
required |
dy
|
float
|
Vertical mesh spacing |
required |
deletemeshoption
|
int
|
Option for clipping mesh. Defaults to 1. |
INSIDE_NOT_INTERSECTED
|
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
None
|
description |
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh2d_add_triangular(network: Network, polygon: Polygon | MultiPolygon, edge_length: float = None) -> None
¶
Add triangular mesh to existing network. An orthogonal mesh is generated by the meshkernel, which likely means that the given geometry is not completely filled. The triangle discretization is determined based on the coordinates on the boundary of the provided geometry. Giving an edge_length will discretize the polygon for you, but you can also do this yourself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network object to which the mesh is added |
required |
polygon
|
Union[Polygon, MultiPolygon]
|
Geometry within which the mesh is generated |
required |
edge_length
|
float
|
Distance for which the polygon boundary is discretized (by approximation). Defaults to None. |
None
|
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh2d_altitude_from_raster(network, rasterpath, where: RasterStatPosition = 'face', stat='mean', fill_option: FillOption = 'fill_value', fill_value=None)
¶
Method to determine level of nodes
This function works faster for large amounts of cells, since it does not draw polygons but checks for nearest neighbours (voronoi) based on interpolation.
Note that the raster is not clipped. Any values outside the bounds are also taken into account.
Source code in hydrolib/dhydamo/geometry/mesh.py
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 856 857 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 | |
mesh2d_clip(network: Network, polygon: GeometryList | (Polygon | MultiPolygon), deletemeshoption: mk.DeleteMeshOption = mk.DeleteMeshOption.INSIDE_AND_INTERSECTED, inside=True) -> None
¶
Clip the mesh (currently implemented for 2d) and clean remaining hanging edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network for which the mesh is clipped |
required |
polygon
|
Union[GeometryList, Union[Polygon, MultiPolygon]]
|
Polygon within which the mesh is clipped |
required |
deletemeshoption
|
int
|
Options for deleting nodes inside/outside polygon. Defaults to 1. |
INSIDE_AND_INTERSECTED
|
inside
|
bool
|
Whether to clip inside or outside the polygon. Defaults to True. |
True
|
Source code in hydrolib/dhydamo/geometry/mesh.py
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 | |
mesh2d_refine(network: Network, polygon: Polygon | MultiPolygon, steps: int, refine_parameters: dict = None) -> None
¶
Refine mesh 2d within (list of) polygon or multipolygon, with a certain number of refinement steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
Network for which the mesh is clipped |
required |
polygon
|
Union[GeometryList, Union[Polygon, MultiPolygon]]
|
Polygon within which the mesh is clipped |
required |
steps
|
int
|
Number of steps in the refinement |
required |
parameters
|
MeshRefinementParameters
|
parameters to be used in the refinement. Defaults to None. |
required |
Source code in hydrolib/dhydamo/geometry/mesh.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 249 250 251 252 253 254 255 256 257 | |
mesh2d_gridgeom
¶
Mesh2D_GG
¶
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 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 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 | |
altitude_from_raster(rasterpath, where='face', stat='mean', missing='default')
¶
Method to determine level of nodes
This function works faster for large amounts of cells, since it does not draw polygons but checks for nearest neighbours (voronoi) based on interpolation.
Note that the raster is not clipped. Any values outside the bounds are also taken into account.
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 | |
clean_nodes(xnodes, ynodes, edge_nodes, face_nodes)
¶
Method to clean the nodes. Edges that do not form a cell are deleted. Alternative method based on checking tuple pairs
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 | |
clip_mesh_by_polygon(polygon, outside=True)
¶
Removes part of the existing mesh within the given polygon.
Parameters¶
polygon : list, Polygon, MultiPolygon A polygon, multi-polygon or list of multiple polygons or multipolygons. The faces within the polygons are removed.
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 | |
clip_nodes(xnodes, ynodes, edge_nodes, polygon, keep_outside=False)
¶
Method that returns a set of nodes that is clipped within a given polygon.
Parameters¶
xnodes : X-coordinates of mesh nodes ynodes : Y-coordinates of mesh nodes edge_nodes : node ids of edges. These are assumed in 1-based numbering polygon : Polygon, Multipolygon or list of
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 | |
faces_to_centroid()
¶
The find_cells function does not always return face coordinates that are all accepted by the interactor. The coordinates are placed on the circumcenters, and placed on the face border in case of a coordinate that is outside the cells.
This function shifts the face coordinates towards the centroid (center of gravity) of the cell.
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
Rectangular
¶
Bases: Mesh2D_GG
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 620 621 622 623 624 625 626 627 628 | |
generate_grid(x0, y0, dx, dy, ncols, nrows, clipgeo=None, rotation=0)
¶
Generate rectangular grid based on the origin (x0, y0) the cell sizes (dx, dy), the number of columns and rows (ncols, nrows) and a rotation in degrees (default=0) A geometry (clipgeo) can be given to clip the grid.
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 | |
generate_within_polygon(polygon, cellsize, rotation=0)
¶
Function to generate a grid within a polygon. It uses the function 'generate_grid' but automatically detects the extent.
Parameters¶
polygon : (list of) shapely.geometry.Polygon or a shapely.geometry.MultiPolygon
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 | |
refine(polygon, level, cellsize, debug=False, dflowfm_path=None)
¶
Parameters¶
polygon : list of tuples Polygon in which to refine level : int Number of times to refine
Source code in hydrolib/dhydamo/geometry/mesh2d_gridgeom.py
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 620 621 622 623 624 625 626 627 628 | |
models
¶
GeometryList
¶
Bases: GeometryList
Source code in hydrolib/dhydamo/geometry/models.py
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 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 | |
geoms
property
¶
Returns GeometryList objects based on spliited by geometries
rasterstats
¶
check_geodateframe_rasterstats(facedata)
¶
Check for type, columns and coordinates
Source code in hydrolib/dhydamo/geometry/rasterstats.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
compress(path)
¶
Function re-save an existing raster file with compression.
Parameters¶
path : str Path to raster file. File is overwritten with compress variant.
Source code in hydrolib/dhydamo/geometry/rasterstats.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
raster_in_parts(f: rasterio.io.DatasetReader, ncols: int, nrows: int, facedata) -> RasterPart
¶
Certain rasters are too big to read into memory at once. This function helps splitting them in equal parts of (+- ncols x nrows pixels)
If facedata is given, each part is extended such that whole faces are covered by the parts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
_type_
|
description |
required |
ncols
|
_type_
|
description |
required |
nrows
|
_type_
|
description |
required |
facedata
|
_type_
|
description |
required |
Yields:
| Name | Type | Description |
|---|---|---|
_type_ |
RasterPart
|
description |
Source code in hydrolib/dhydamo/geometry/rasterstats.py
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 | |
raster_stats_fine_cells(rasterpath: str | Path, facedata, stats=['mean'])
¶
Calculate statistic from a raster, where the raster resoltion is (much) smaller than the cell size.
Parameters¶
rasterpath : str Path to raster file facedata : geopandas.GeoDataFrame Dataframe with polygons in which the raster statistics are derived. stats : list List of statistics to retrieve. Should be numpy functions that require one argument
Source code in hydrolib/dhydamo/geometry/rasterstats.py
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 | |
waterdepth_ahn(dempath, facedata, outpath, column)
¶
Function that combines a dem and water levels to a water depth raster. No sub grid correction is done.
Parameters¶
dempath : str Path to raster file with terrain level facedata : gpd.GeoDataFrame GeoDataFrame with at least the cell geometry and a column with water levels outpath : str Path to output raster file column : str Name of the column with the water level data
Source code in hydrolib/dhydamo/geometry/rasterstats.py
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 | |
spatial
¶
find_nearest_branch(branches, geometries, method='overal', maxdist=5)
¶
Method to determine nearest branch for each geometry. The nearest branch can be found by finding t from both ends (ends) or the nearest branch from the geometry as a whole (overal), the centroid (centroid), or intersecting (intersect).
Parameters¶
branches : geopandas.GeoDataFrame Geodataframe with branches geometries : geopandas.GeoDataFrame Geodataframe with geometries to snap method='overal' : str Method for determine branch maxdist=5 : int or float Maximum distance for finding nearest geometry minoffset : int or float Minimum offset from the end of the corresponding branch in case of method=equal
Source code in hydrolib/dhydamo/geometry/spatial.py
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 | |
get_voronoi_around_nodes(nodes: np.ndarray, facedata: gpd.GeoDataFrame) -> gpd.GeoDataFrame
¶
Creates voronoi polygons around face nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
ndarray
|
xy coordinates of face nodes |
required |
facedata
|
GeoDataFrame
|
GeoDataFrame with face properties |
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: Creating GeoDataFrame with created polygons and their properties |
Source code in hydrolib/dhydamo/geometry/spatial.py
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 | |
minimum_bounds_fixed_rotation(polygon, angle)
¶
Get the minimum box for a polygon with a given axes rotation.
Parameters¶
polygon : shapely.geometry.Polygon Polygon that is rotated angle : int or float Rotation of the polygon in degrees
Returns¶
tuple Tuple with origin (x, y), xsize and ysize
Source code in hydrolib/dhydamo/geometry/spatial.py
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 | |
orthogonal_line(line: LineString, offset: float, width: float = 1.0) -> list[tuple[float]]
¶
Parameters¶
line : shapely.geometry.LineString Line geometry object on which the orthogonal line is drawn offset : float Offset of the orthogonal line along line width : float Width of the orthogonal line
Returns¶
line : list List with coordinate tuples
Source code in hydrolib/dhydamo/geometry/spatial.py
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 | |
points_in_polygon(points: np.ndarray, polygon: Polygon) -> np.ndarray
¶
Determine points that are inside a polygon, taking holes into account.
Parameters¶
points : numpy.array Nx2 - array polygon : shapely.geometry.Polygon Polygon (can have holes)
Source code in hydrolib/dhydamo/geometry/spatial.py
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 | |
possibly_intersecting(dataframebounds, geometry, buffer=0)
¶
Finding intersecting profiles for each branch is a slow process in case of large datasets To speed this up, we first determine which profile intersect a square box around the branch With the selection, the interseting profiles can be determines much faster.
Parameters¶
dataframebounds : numpy.array geometry : shapely.geometry.Polygon
Source code in hydrolib/dhydamo/geometry/spatial.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
rotate_coordinates(origin, theta, xcrds, ycrds)
¶
Rotate coordinates around origin (x0, y0) with a certain angle (radians)
Source code in hydrolib/dhydamo/geometry/spatial.py
23 24 25 26 27 28 29 30 | |