@@ -14,27 +14,40 @@ Base.size(b::GDALBand) = b.size
1414DiskArrays. eachchunk (b:: GDALBand ) = b. cs
1515DiskArrays. haschunks (:: GDALBand ) = DiskArrays. Chunked ()
1616
17+ # function DiskArrays.readblock!(b::GDALBand, aout::Matrix, r::AbstractUnitRange...)
18+ # AG.read(b.filename) do ds
19+ # AG.getband(ds, b.band) do bh
20+ # DiskArrays.readblock!(bh, aout, r...)
21+ # end
22+ # end
23+ # end
1724function DiskArrays. readblock! (b:: GDALBand , aout:: Matrix , r:: AbstractUnitRange... )
18- AG. read (b. filename) do ds
19- AG. getband (ds, b. band) do bh
20- DiskArrays. readblock! (bh, aout, r... )
21-
25+ chunk_size = size (first (b. cs))
26+ chunk_indices = [div .(extrema (r[i]) .- 1 , chunk_size[i]) .+ 1 for i in 1 : 2 ]
27+
28+ AG. read (b. filename) do ds
29+ 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 ])
35+ 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
39+ end
40+ end
2241 end
2342 end
24- end
25-
26- function DiskArrays. readblock! (b:: GDALBand , aout, r:: AbstractUnitRange... )
43+ end
44+ function DiskArrays. readblock! (b:: GDALBand , aout:: AbstractArray , r:: AbstractUnitRange... )
2745 aout2 = similar (aout)
2846 DiskArrays. readblock! (b, aout2, r)
2947 aout .= aout2
30- end
31-
32- function DiskArrays. readblock! (b:: GDALBand , aout:: Matrix , r:: Tuple{AbstractUnitRange, AbstractUnitRange} )
33- AG. read (b. filename) do ds
34- AG. getband (ds, b. band) do bh
35- DiskArrays. readblock! (bh, aout, r... )
36- end
37- end
48+ end
49+ function DiskArrays. readblock! (b:: GDALBand , aout:: AbstractArray , r:: Tuple{AbstractUnitRange, AbstractUnitRange} )
50+ DiskArrays. readblock! (b, aout, r... )
3851end
3952
4053function DiskArrays. writeblock! (b:: GDALBand , ain, r:: AbstractUnitRange... )
0 commit comments