Skip to content

Commit

Permalink
update refdims on getindex from RasterSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Sep 26, 2023
1 parent a0f6184 commit 70175b7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ function Base.map(f, series::RasterSeries)
end
end

@propagate_inbounds function Base.getindex(A::AbstractRasterSeries, i::Integer)
# Add refdims from the series
x = parent(A)[i]
_, refdims = DD.slicedims(getindex, dims(A), (), (i,))
return rebuild(x; refdims)
end
@propagate_inbounds function Base.getindex(A::AbstractRasterSeries, i1::StandardIndices, i2::StandardIndices, I::StandardIndices...)
I = to_indices(A, (i1, i2, I...))
x = Base.$f(parent(A), I...)
if all(i -> i isa Integer, I)
# Add refdims from the series
_, refdims = DD.slicedims(A, I...)
return rebuild(x; refdims)
else
return rebuildsliced(Base.$f, A, x, I)
end
end

# Swap in the filename/s of an object for another filename, wherever it is.
# This is used to use already loaded metadata of one file with another
# file that is similar or identical besides tha actual raster data.
Expand All @@ -226,3 +244,4 @@ function swap_filename(x::AbstractArray, filename::AbstractString)
@set fa.filename = filename
end
end

0 comments on commit 70175b7

Please sign in to comment.