From 0e664e5c6be191cdd0de6b968b95d82d3e3b84f4 Mon Sep 17 00:00:00 2001 From: Hofer-Julian Date: Fri, 5 Apr 2024 14:41:15 +0200 Subject: [PATCH] Add `Model.to_crs` method in order to reproject Fixes #1354 --- python/ribasim/ribasim/model.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/ribasim/ribasim/model.py b/python/ribasim/ribasim/model.py index ccca20892..b05937656 100644 --- a/python/ribasim/ribasim/model.py +++ b/python/ribasim/ribasim/model.py @@ -182,14 +182,20 @@ def _save(self, directory: DirectoryPath, input_dir: DirectoryPath): sub._save(directory, input_dir) def set_crs(self, crs: str) -> None: + self._apply_spatial_function("set_crs", crs) + + def to_crs(self, crs: str) -> None: + self._apply_spatial_function("to_crs", crs) + + def _apply_spatial_function(self, function_name: str, crs: str) -> None: self.crs = crs - self.edge.df = self.edge.df.set_crs(crs) + self.edge.df = getattr(self.edge.df, function_name)(crs) for sub in self._nodes(): if sub.node.df is not None: - sub.node.df = sub.node.df.set_crs(crs) + sub.node.df = getattr(sub.node.df, function_name)(crs) for table in sub._tables(): if isinstance(table, SpatialTableModel) and table.df is not None: - table.df = table.df.set_crs(crs) + table.df = getattr(table.df, function_name)(crs) def node_table(self) -> NodeTable: """Compute the full NodeTable from all node types."""