From 22c429f3c8cce66cac6eba6a81605c50c36a608c Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 24 Nov 2023 14:45:03 +0100 Subject: [PATCH] updates --- src/methods/crop_extend.jl | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/methods/crop_extend.jl b/src/methods/crop_extend.jl index 04c8db8ff..77d95c3e8 100644 --- a/src/methods/crop_extend.jl +++ b/src/methods/crop_extend.jl @@ -172,27 +172,25 @@ function _extend_to(x::RasterStackOrArray, to; kw...) end function _extend_to(A::AbstractRaster, to::DimTuple; - filename=nothing, suffix=nothing, touches=false + filename=nothing, suffix=nothing, touches=false, missingval=missingval(A) ) others = otherdims(to, A) # Allow not specifying all dimensions to = (set(dims(A), map(=>, dims(A, to), to)...)..., others...) # Calculate the range of the old array in the extended array - ranges = _without_mapped_crs(A) do A + rangedims = _without_mapped_crs(A) do A _without_mapped_crs(to) do to - map(dims(A), to) do d, t - range = if touches - DD.selectindices(t, LA.Touches(bounds(d))) - else - DD.selectindices(t, LA.ClosedInterval(bounds(d)...)) - end - rebuild(d, range) + map(dims(A, to), to) do d, t + # Values must match exactly, so use `At` + DD.selectindices(t, At(first(d))):DD.selectindices(t, At(last(d))) end end end + others = otherdims(to, A) + final_to = (set(dims(A), map(=>, dims(A, to), to)...)..., others...) # Create a new extended array - newA = create(filename, eltype(A), to; - suffix, parent=parent(A), missingval=missingval(A), + newA = create(filename, eltype(A), final_to; + suffix, parent=parent(A), missingval, name=name(A), metadata=metadata(A) ) # Input checks @@ -208,15 +206,15 @@ function _extend_to(A::AbstractRaster, to::DimTuple; end end # The missingval may have changed for disk-based arrays - if !isequal(missingval(A), missingval(newA)) - A = replace_missing(A, missingval(newA)) + if !isequal(missingval, Rasters.missingval(newA)) + A = replace_missing(A, Rasters.missingval(newA)) end open(newA; write=true) do O # Fill it with missing/nodata values - O .= missingval(O) + O .= Rasters.missingval(O) # Copy the original data to the new array # Somehow this is slow from disk? - broadcast_dims!(identity, view(O, ranges...), A) + broadcast_dims!(identity, view(O, rangedims...), A) end return newA end