Skip to content

Commit

Permalink
allow specifying dims to crop
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfreu committed Oct 19, 2023
1 parent 10c6c08 commit e0219e2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/methods/crop_extend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ 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
lookup(d) isa AbstractSampled ? (acc..., d) : acc
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
Expand Down

0 comments on commit e0219e2

Please sign in to comment.