Skip to content

Commit

Permalink
fix geom_component._region_data() (#1091)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Vente <[email protected]>
  • Loading branch information
veenstrajelmer and savente93 authored Oct 23, 2024
1 parent 5723642 commit 416c889
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
34 changes: 17 additions & 17 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ All notable changes to this project will be documented in this page.
The format is based on `Keep a Changelog`_, and this project adheres to
`Semantic Versioning`_.


Unreleased
==========

New
---

Changed
-------

Fixed
-----
- Fixed incorrect arguments causing crashes in geom_component._region_data() (#1091)

Deprecated
----------

V1
==

Expand Down Expand Up @@ -52,23 +69,6 @@ Removed
- The function `hydromt.gis.flw.basinmap` has been removed in favour of `hydromt.gis.flw.basin_map`. (#987)
- Support for using the `within` predicate in the function `get_basin_geometry` has been removed. (#987)



Unreleased
==========

New
---

Changed
-------

Fixed
-----

Deprecated
----------

v1.0.0 (2024-09-26)
===================

Expand Down
12 changes: 5 additions & 7 deletions hydromt/model/components/geoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ def _region_data(self) -> Optional[GeoDataFrame]:
return None
bounds = np.column_stack([geom.bounds for geom in self.data.values()])
total_bounds = (
bounds[0].min(),
bounds[1].min(),
bounds[2].max(),
bounds[3].max(),
)
region = gpd.GeoDataFrame(
geometry=[gpd.GeoSeries(box(total_bounds))], crs=self.model.crs
bounds[:, 0].min(),
bounds[:, 1].min(),
bounds[:, 2].max(),
bounds[:, 3].max(),
)
region = gpd.GeoDataFrame(geometry=[box(*total_bounds)], crs=self.model.crs)

return region

Expand Down
6 changes: 5 additions & 1 deletion tests/components/test_geoms_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import cast

import geopandas as gpd
import numpy as np
from pyproj import CRS
from pytest_mock import MockerFixture
from shapely.geometry import box
Expand All @@ -14,7 +15,8 @@


def test_model_set_geoms(tmpdir):
bbox = box(*[4.221067, 51.949474, 4.471006, 52.073727], ccw=True)
bbox_list = [4.221067, 51.949474, 4.471006, 52.073727]
bbox = box(*bbox_list, ccw=True)
geom = gpd.GeoDataFrame(geometry=[bbox], crs=4326)

model = Model(root=str(tmpdir), mode="w")
Expand All @@ -25,6 +27,8 @@ def test_model_set_geoms(tmpdir):

assert list(geom_component.data.keys()) == ["geom_wgs84"]
assert list(geom_component.data.values())[0].equals(geom)
expected_bounds = np.array([bbox_list])
assert np.allclose(geom_component._region_data.bounds.values, expected_bounds)


def test_model_read_geoms(tmpdir):
Expand Down

0 comments on commit 416c889

Please sign in to comment.