Skip to content

Commit

Permalink
Copy over the required shapefile files upon saving forcing
Browse files Browse the repository at this point in the history
  • Loading branch information
BSchilperoort committed Sep 5, 2024
1 parent d121adf commit f5d65e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ewatercycle/base/forcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,16 @@ def save(self):
# Copy shapefile so statistics like area can be derived
if clone.shape is not None:
if not clone.shape.is_relative_to(clone.directory):
clone.shape = Path(
new_shp_path = Path(
shutil.copy(clone.shape, clone.directory / clone.shape.name)
)
# Also copy other required files:
for ext in [".dbf", ".shx", ".prj"]:
shutil.copy(
clone.shape.with_suffix(ext),
clone.directory / clone.shape.with_suffix(ext).name,
)
clone.shape = new_shp_path
clone.shape = clone.shape.relative_to(clone.directory)

fdict = clone.model_dump(exclude={"directory"}, exclude_none=True, mode="json")
Expand Down
4 changes: 4 additions & 0 deletions tests/src/base/test_forcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def test_save(self, tmp_path: Path, sample_shape: str):

assert content == expected

# make sure all mandatory (shape)files exist
for ext in [".dbf", ".prj", ".shp", ".shx"]:
assert (forcing.directory / forcing.shape.with_suffix(ext)).exists()


class TestGenericDistributedForcingWithInternalShape:
def test_save(self, tmp_path: Path, sample_shape: str):
Expand Down

0 comments on commit f5d65e5

Please sign in to comment.