From e8d47cccdba7640c485c21d769125e260a05d4ad Mon Sep 17 00:00:00 2001 From: Bas des Tombe Date: Mon, 23 Dec 2024 11:35:18 +0100 Subject: [PATCH] Rotate the polygon instead of the modelgrid --- nlmod/dims/grid.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nlmod/dims/grid.py b/nlmod/dims/grid.py index f4bb25d8..31acad10 100644 --- a/nlmod/dims/grid.py +++ b/nlmod/dims/grid.py @@ -1680,9 +1680,17 @@ def gdf_to_bool_da( if buffer != 0.0: multipolygon = multipolygon.buffer(buffer) + # Rotate the polygon instead of the modelgrid if ix is None: - modelgrid = modelgrid_from_ds(ds) + modelgrid = modelgrid_from_ds(ds, rotated=False) ix = GridIntersect(modelgrid, method="vertex") + + grid_rotation = ds.attrs.get("angrot", 0.0) + ix_rotation = ix.mfgrid.angrot + + if grid_rotation != 0.0 and ix_rotation == 0.0: + affine = get_affine_mod_to_world(ds) + multipolygon = affine_transform_gdf(multipolygon, affine) if kwargs or contains_centroid or min_area_fraction is not None: r = ix.intersect(