Skip to content

Commit ee744d6

Browse files
committed
Add validation checks for geometry and export path adjustment in lakes_pwn script
1 parent 39ee8f3 commit ee744d6

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/nhflodata/data/mockup/lakes_pwn/v1.0.0/lakes_pwn.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Create Lakes input file for dunes."""
22

3+
from pathlib import Path
4+
35
import geopandas as gpd
4-
import pandas as pd
56
from nhflotools.geoconverter.utils import round_bounds, validate_crs, validate_geometry
67
from nlmod.gwf.lake import LAKE_KWDS, OUTLET_DEFAULT
78

@@ -110,4 +111,17 @@
110111

111112
# Export to sanitized GeoJSON
112113
gdf_lake = gdf_lake.astype(dtypes)
113-
gdf_lake.to_file("lakes_pwn.geojson", driver="GeoJSON", write_bbox=True, coordinate_precision=2)
114+
115+
# Checks
116+
validate_crs(gdf_lake)
117+
for idx, geom in enumerate(gdf_lake.geometry):
118+
is_valid, error = validate_geometry(geom)
119+
if not is_valid:
120+
msg = f"Geometry at index {idx} is invalid: {error}"
121+
raise ValueError(msg)
122+
123+
out_geojson = Path(__file__).parent / "lakes_pwn.geojson"
124+
gdf_lake.to_file(out_geojson, driver="GeoJSON", write_bbox=True, coordinate_precision=2)
125+
126+
bounds = dict(zip(["minx", "miny", "maxx", "maxy"], gdf_lake.total_bounds, strict=False))
127+
print("extent:", round_bounds(bounds, rounding_interval=1000.0).values()) # noqa: T201

0 commit comments

Comments
 (0)