From e0219e2b5110ccfa35efb4d9146392688f6aa656 Mon Sep 17 00:00:00 2001 From: maxfreu Date: Thu, 19 Oct 2023 09:56:15 +0000 Subject: [PATCH] allow specifying dims to crop --- src/methods/crop_extend.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/methods/crop_extend.jl b/src/methods/crop_extend.jl index 2ae57366c..e19e4220b 100644 --- a/src/methods/crop_extend.jl +++ b/src/methods/crop_extend.jl @@ -92,7 +92,10 @@ function _crop_to(x, to; kw...) return _crop_to(x, ext; kw...) end end -_crop_to(A, to::RasterStackOrArray; kw...) = _crop_to(A, dims(to); kw...) +function _crop_to(A, to::RasterStackOrArray; kw...) + target_dims = get(kw, :dims, name.(dims(to))) + return _crop_to(A, dims(to, target_dims); kw...) +end function _crop_to(x, to::DimTuple; kw...) # We can only crop to sampled dims (e.g. not categorical dims like Band) sampled = reduce(to; init=()) do acc, d @@ -100,7 +103,7 @@ function _crop_to(x, to::DimTuple; kw...) end return _crop_to(x, Extents.extent(to); kw...) end -function _crop_to(x, to::Extents.Extent; touches=false) +function _crop_to(x, to::Extents.Extent; touches=false, kw...) ds = dims(x, map(key2dim, keys(to))) # Take a view over the bounds _without_mapped_crs(x) do x1