Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use geometries from schematisation for pipe, weir and orifice #410

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changelog of threedigrid-builder
1.22.1 (unreleased)
-------------------

- Nothing changed yet.
- Use pipe.geom, weir.geom and orifice.weir to build gridadmin


1.22.0 (2025-01-08)
Expand Down
2 changes: 2 additions & 0 deletions threedigrid_builder/grid/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class WeirOrifice: # NL: stuw / doorlaat
zoom_category: int
display_name: str
sewerage: int
the_geom: shapely.Geometry


class WeirOrifices(Array[WeirOrifice]):
Expand Down Expand Up @@ -114,6 +115,7 @@ def get_lines(self, connection_nodes, line_id_counter, connection_node_offset=0)
return Lines(
id=itertools.islice(line_id_counter, len(self)),
line=line,
line_geometries=self.the_geom,
content_type=self.content_type,
content_pk=self.id,
kcu=self.crest_type, # implicitly converts CalculationType -> LineType
Expand Down
6 changes: 6 additions & 0 deletions threedigrid_builder/interface/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ def get_orifices(self) -> Orifices:
models.Orifice.discharge_coefficient_positive,
models.Orifice.display_name,
models.Orifice.sewerage,
models.Orifice.geom.label("the_geom"),
case(
{
models.Orifice.friction_value.isnot(None)
Expand Down Expand Up @@ -754,6 +755,7 @@ def get_orifices(self) -> Orifices:
)
# map friction_type 4 to friction_type 2 to match crosssectionlocation enum
arr["friction_type"][arr["friction_type"] == 4] = 2
arr["the_geom"] = self.reproject(arr["the_geom"])

return Orifices(**{name: arr[name] for name in arr.dtype.names})

Expand All @@ -774,6 +776,7 @@ def get_pipes(self) -> Pipes:
models.Pipe.hydraulic_conductivity_out,
models.Pipe.hydraulic_conductivity_in,
models.Pipe.material_id.label("material"),
models.Pipe.geom.label("the_geom"),
case(
{
models.Pipe.friction_value.isnot(None)
Expand Down Expand Up @@ -803,6 +806,7 @@ def get_pipes(self) -> Pipes:
arr["friction_type"][arr["friction_type"] == 4] = 2
arr["hydraulic_conductivity_out"] /= DAY_IN_SECONDS
arr["hydraulic_conductivity_in"] /= DAY_IN_SECONDS
arr["the_geom"] = self.reproject(arr["the_geom"])

# transform to a Pipes object
return Pipes(**{name: arr[name] for name in arr.dtype.names})
Expand Down Expand Up @@ -848,6 +852,7 @@ def get_weirs(self) -> Weirs:
models.Weir.discharge_coefficient_positive,
models.Weir.display_name,
models.Weir.sewerage,
models.Weir.geom.label("the_geom"),
case(
{
models.Weir.friction_value.isnot(None)
Expand All @@ -874,6 +879,7 @@ def get_weirs(self) -> Weirs:
)
# map friction_type 4 to friction_type 2 to match crosssectionlocation enum
arr["friction_type"][arr["friction_type"] == 4] = 2
arr["the_geom"] = self.reproject(arr["the_geom"])

return Weirs(**{name: arr[name] for name in arr.dtype.names})

Expand Down
10 changes: 10 additions & 0 deletions threedigrid_builder/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ def test_get_pipes(db):
assert pipes.friction_type[28] == FrictionType.MANNING
assert pipes.friction_value[36] == 0.0145
assert pipes.display_name[33] == "71518_71517"
assert_geometries_equal(
pipes.the_geom[0],
shapely.from_wkt("LINESTRING (110267.3 517868.8, 110264.3 517863.5)"),
tolerance=1,
)


def test_get_settings(db):
Expand Down Expand Up @@ -379,6 +384,11 @@ def test_get_weirs(db):
assert weirs.friction_value[36] == 0.03
assert weirs.display_name[33] == "KST-JL-76"
assert weirs.sewerage[0] == 1
assert_geometries_equal(
weirs.the_geom[0],
shapely.from_wkt("LINESTRING (110278.3 517669.1, 110276.3 517669.8)"),
tolerance=1,
)


def test_get_dem_average(db):
Expand Down
Loading