-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new function create mask hydro buffer
- Loading branch information
1 parent
06f8e6b
commit 0be63c9
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
lidro/create_virtual_point/vectors/create_mask_hydro_buffer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
""" Extract a Z elevation value every N meters along the hydrographic skeleton | ||
""" | ||
import geopandas as gpd | ||
from shapely.geometry import CAP_STYLE, MultiPolygon | ||
|
||
|
||
def apply_buffers_to_geometry(hydro_mask: gpd.GeoDataFrame, buffer: float) -> MultiPolygon: | ||
"""Buffer geometry | ||
Objective: create a HYDRO mask largest | ||
Args: | ||
hydro_mask (gpd.GeoDataFrame): geopandas dataframe with input geometry | ||
buffer (float): buffer to apply to the input geometry | ||
Returns: | ||
MutliPolygon: Mask Hydro with buffer | ||
""" | ||
# Buffer | ||
geom = hydro_mask.buffer(buffer, cap_style=CAP_STYLE.square) | ||
return geom | ||
|
||
|
||
def create_mask_hydro_buffer(file_mask: str, buffer: float, crs: str | int) -> gpd.GeoDataFrame: | ||
"""Apply buffer (2 meters by default) from Mask Hydro | ||
Args: | ||
file_mask (str): Path from Mask Hydro | ||
buffer (float): buffer to apply to the input geometry | ||
crs (str | int): Make a CRS from an EPSG code : CRS WKT string | ||
Returns: | ||
gpd.GeoDataFrame : geometry columns are encoded to WKT | ||
""" | ||
# Read Mask Hydro merged | ||
gdf = gpd.read_file(file_mask, crs=crs).unary_union | ||
|
||
# Apply buffer (2 meters by default) from Mask Hydro | ||
gdf = apply_buffers_to_geometry(gdf, buffer) | ||
|
||
return gdf |