Skip to content

Commit

Permalink
add warning for CRS and comments to make it easier to read river_boun…
Browse files Browse the repository at this point in the history
…dary_points
  • Loading branch information
DirkEilander committed Nov 9, 2023
1 parent 96d53f3 commit e4bab49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hydromt_sfincs/sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,8 @@ def setup_river_inflow(
river_len=river_len,
river_upa=river_upa,
inflow=True,
reverse_river_geom = reverse_river_geom,
reverse_river_geom=reverse_river_geom,
logger=self.logger,
)
n = len(gdf_src.index)
self.logger.info(f"Found {n} river inflow points.")
Expand Down Expand Up @@ -971,7 +972,8 @@ def setup_river_outflow(
river_len=river_len,
river_upa=river_upa,
inflow=False,
reverse_river_geom = reverse_river_geom,
reverse_river_geom=reverse_river_geom,
logger=self.logger,
)

if len(gdf_out) > 0:
Expand Down
8 changes: 8 additions & 0 deletions hydromt_sfincs/workflows/flwdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def river_boundary_points(
river_len: float = 1e3,
inflow: bool = True,
reverse_river_geom: bool = False,
logger: logging.Logger = logger,
) -> Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]:
"""Returns the locations where a river flows in (`inflow=True`)
or out (`inflow=False`) of the model region.
Expand Down Expand Up @@ -109,6 +110,11 @@ def river_boundary_points(
region.geometry.type == "Polygon"
):
raise ValueError("Boundary must be a GeoDataFrame of LineStrings.")
if res > 0.01 and region.crs.is_geographic:
# provide warning
logger.warning(
"The region crs is geographic, while the resolution seems to be in meters."
)

if gdf_riv is None and (da_flwdir is None or da_uparea is None):
raise ValueError("Either gdf_riv or da_flwdir and da_uparea must be provided.")
Expand All @@ -124,6 +130,8 @@ def river_boundary_points(
gdf_riv = gdf_riv[gdf_riv["uparea"] >= river_upa]
if "rivlen" in gdf_riv.columns:
gdf_riv = gdf_riv[gdf_riv["rivlen"] > river_len]
# a positive dx results in a point near the start of the line (inflow)
# a negative dx results in a point near the end of the line (outflow)
dx = res / 5 if inflow else -res / 5
if reverse_river_geom:
dx = -dx
Expand Down

0 comments on commit e4bab49

Please sign in to comment.