Skip to content

Commit

Permalink
Add Model.to_crs method in order to reproject
Browse files Browse the repository at this point in the history
Fixes #1354
  • Loading branch information
Hofer-Julian committed Apr 5, 2024
1 parent 5d2bbef commit 0e664e5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 188 in python/ribasim/ribasim/model.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/model.py#L188

Added line #L188 was not covered by tests

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."""
Expand Down

0 comments on commit 0e664e5

Please sign in to comment.