@@ -22,20 +22,20 @@ DiskArrays.haschunks(::GDALBand) = DiskArrays.Chunked()
2222# end
2323# end
2424function DiskArrays. readblock! (b:: GDALBand , aout:: Matrix , r:: AbstractUnitRange... )
25- chunk_size = size (first (b. cs))
26- chunk_indices = [div .(extrema (r[i]) .- 1 , chunk_size[i]) .+ 1 for i in 1 : 2 ]
25+ chunk_size = b. cs. chunks. ranges
26+ # Calculate chunk indices for all dimensions
27+ chunk_indices = [(div (first (r[i])- 1 , length (chunk_size[i]))+ 1 ): (div (last (r[i])- 1 , length (chunk_size[i]))+ 1 )
28+ for i in eachindex (r)]
2729
2830 AG. read (b. filename) do ds
2931 AG. getband (ds, b. band) do bh
30- for i in chunk_indices[1 ][1 ]: chunk_indices[1 ][2 ], j in chunk_indices[2 ][1 ]: chunk_indices[2 ][2 ]
31- chunk = b. cs[i,j]
32- overlap = (intersect (r[1 ], chunk[1 ]), intersect (r[2 ], chunk[2 ]))
33-
34- if ! isempty (overlap[1 ]) && ! isempty (overlap[2 ])
32+ for chunk_idx in CartesianIndices (Tuple (chunk_indices))
33+ chunk = b. cs[chunk_idx... ]
34+ overlap = tuple ((intersect (r[i], chunk[i]) for i in eachindex (r)). .. )
35+ if all (x -> ! isempty (x), overlap)
3536 chunk_data = AG. read (bh, overlap... )
36-
37- aout_indices = (overlap[1 ] .- first (r[1 ]) .+ 1 , overlap[2 ] .- first (r[2 ]) .+ 1 )
38- aout[aout_indices... ] .= chunk_data
37+ aout_indices = tuple ((overlap[i] .- first (r[i]) .+ 1 for i in eachindex (r)). .. )
38+ view (aout, aout_indices... ) .= chunk_data
3939 end
4040 end
4141 end
0 commit comments