From e88317f6bfea75cd999610b8114754f7cd16e603 Mon Sep 17 00:00:00 2001 From: margrietpalm Date: Tue, 10 Dec 2024 01:35:01 -0800 Subject: [PATCH 1/5] Limit changed names to database interface (#403) * Rename usage of geom back to the_geom so this rename is only reflected in the interface * Replace usage of arr_to_attr_dict with label in sql query --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8831f42d..4ff0d615 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ Changelog of threedigrid-builder 1.22.1 (unreleased) ------------------- -- Nothing changed yet. +- Remove internal changes made for previous schema upgrades and limit changes to db interface 1.22.0 (2025-01-08) From f10846450113a12ed91258bb3a6dd31c41498715 Mon Sep 17 00:00:00 2001 From: Margriet Palm Date: Wed, 15 Jan 2025 09:21:11 +0100 Subject: [PATCH 2/5] Read pipe geometry from schematisation --- threedigrid_builder/interface/db.py | 2 ++ threedigrid_builder/tests/test_db.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/threedigrid_builder/interface/db.py b/threedigrid_builder/interface/db.py index ffc02a53..57a13d8e 100644 --- a/threedigrid_builder/interface/db.py +++ b/threedigrid_builder/interface/db.py @@ -774,6 +774,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) @@ -803,6 +804,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}) diff --git a/threedigrid_builder/tests/test_db.py b/threedigrid_builder/tests/test_db.py index dc3c6a30..5a5a1112 100644 --- a/threedigrid_builder/tests/test_db.py +++ b/threedigrid_builder/tests/test_db.py @@ -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): From f7fcb380a427ef2459f4e1d9a85c334a69227e8b Mon Sep 17 00:00:00 2001 From: Margriet Palm Date: Wed, 15 Jan 2025 09:27:24 +0100 Subject: [PATCH 3/5] Read geometries from schematisation for weir and orifice --- threedigrid_builder/grid/structures.py | 1 + threedigrid_builder/interface/db.py | 4 ++++ threedigrid_builder/tests/test_db.py | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/threedigrid_builder/grid/structures.py b/threedigrid_builder/grid/structures.py index fb695d64..7cfd589c 100644 --- a/threedigrid_builder/grid/structures.py +++ b/threedigrid_builder/grid/structures.py @@ -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]): diff --git a/threedigrid_builder/interface/db.py b/threedigrid_builder/interface/db.py index 57a13d8e..59f18c69 100644 --- a/threedigrid_builder/interface/db.py +++ b/threedigrid_builder/interface/db.py @@ -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) @@ -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}) @@ -850,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) @@ -876,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}) diff --git a/threedigrid_builder/tests/test_db.py b/threedigrid_builder/tests/test_db.py index 5a5a1112..0f1d396c 100644 --- a/threedigrid_builder/tests/test_db.py +++ b/threedigrid_builder/tests/test_db.py @@ -384,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): From b80aca38e15ea547594afdd2c0e45cdc1ca04b70 Mon Sep 17 00:00:00 2001 From: Margriet Palm Date: Wed, 15 Jan 2025 09:44:15 +0100 Subject: [PATCH 4/5] Use weir and orifice geom when creating lines --- threedigrid_builder/grid/structures.py | 1 + 1 file changed, 1 insertion(+) diff --git a/threedigrid_builder/grid/structures.py b/threedigrid_builder/grid/structures.py index 7cfd589c..b08222a0 100644 --- a/threedigrid_builder/grid/structures.py +++ b/threedigrid_builder/grid/structures.py @@ -115,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 From 253d14454ddb86b78dd2ca9ec953b0b7e54af2bb Mon Sep 17 00:00:00 2001 From: Margriet Palm Date: Wed, 15 Jan 2025 09:51:12 +0100 Subject: [PATCH 5/5] update changes --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4ff0d615..c7a8c681 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ Changelog of threedigrid-builder 1.22.1 (unreleased) ------------------- -- Remove internal changes made for previous schema upgrades and limit changes to db interface +- Use pipe.geom, weir.geom and orifice.weir to build gridadmin 1.22.0 (2025-01-08)