Skip to content

Commit

Permalink
bugfix extend
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Nov 22, 2023
1 parent f25515f commit d9a2ab0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/methods/crop_extend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ end
function _extend_to(A::AbstractRaster, to::DimTuple;
filename=nothing, suffix=nothing, touches=false
)
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
_without_mapped_crs(to) do to
Expand All @@ -192,6 +195,18 @@ function _extend_to(A::AbstractRaster, to::DimTuple;
suffix, parent=parent(A), missingval=missingval(A),
name=name(A), metadata=metadata(A)
)
# Input checks
map(dims(A, to), dims(newA, to)) do d1, d2
if lookup(d1) isa Union{AbstractSampled,NoLookup}
b1, b2 = bounds(d1), bounds(d2)
b1[1] >= b2[1] || throw(ArgumentError("Lower bound of $(basetypeof(d1)) lookup of `$(b2[1])` are not larger than the original `$(b1[1])`"))
b1[2] <= b2[2] || throw(ArgumentError("Upper bound of $(basetypeof(d2)) lookup of `$(b2[2])` is not larger than the original `$(b1[2])`"))
elseif lookup(d1) isa Categorical
map(lookup(d1)) do x
x in d2 || throw(ArgumentError("category $x not in new dimension"))
end
end
end
# The missingval may have changed for disk-based arrays
if !isequal(missingval(A), missingval(newA))
A = replace_missing(A, missingval(newA))
Expand Down

0 comments on commit d9a2ab0

Please sign in to comment.