Skip to content

Commit 1d350b1

Browse files
committed
do open read
1 parent 370ea14 commit 1d350b1

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

ext/ArchGDALExt/archgdaldataset.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ DiskArrays.haschunks(::GDALBand) = DiskArrays.Chunked()
2222
# end
2323
# end
2424
function DiskArrays.readblock!(b::GDALBand, aout::Matrix, r::AbstractUnitRange...)
25-
for chunk in eachchunk(b)
26-
overlap = tuple((intersect(r[i], chunk[i]) for i in eachindex(r))...)
27-
if all(x -> !isempty(x), overlap)
28-
chunk_data = AG.read(b.filename, overlap...)
29-
aout_indices = tuple((overlap[i] .- first(r[i]) .+ 1 for i in eachindex(r))...)
30-
view(aout, aout_indices...) .= chunk_data
25+
# Open the dataset before reading
26+
AG.read(b.filename) do ds
27+
# Get the correct band from the dataset
28+
AG.getband(ds, b.band) do bh
29+
for chunk in eachchunk(b)
30+
overlap = tuple((intersect(r[i], chunk[i]) for i in eachindex(r))...)
31+
if all(x -> !isempty(x), overlap)
32+
# Read the chunk data from the band `bh` for the overlapping ranges
33+
chunk_data = AG.read(bh, overlap...)
34+
aout_indices = tuple((overlap[i] .- first(r[i]) .+ 1 for i in eachindex(r))...)
35+
view(aout, aout_indices...) .= chunk_data
36+
end
37+
end
3138
end
3239
end
3340
end

0 commit comments

Comments
 (0)