@@ -14,45 +14,15 @@ 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
2417function DiskArrays. readblock! (b:: GDALBand , aout:: Matrix , r:: AbstractUnitRange... )
25- AG. read (b. filename) do ds
26- AG. getband (ds, b. band) do bh
27- xsize, ysize = AG. width (bh), AG. height (bh)
28- for chunk in eachchunk (b)
29- # Compute overlap between the requested range and the current chunk range
30- overlap = tuple (intersect (r[i], chunk[i]) for i in eachindex (r))
31- overlap_clipped = (
32- clip_overlap (overlap[1 ], xsize), # Clip x-range to raster width
33- clip_overlap (overlap[2 ], ysize) # Clip y-range to raster height
34- )
35- if all (x -> ! isempty (x), overlap_clipped)
36- chunk_data = AG. read (bh, overlap_clipped... )
37- aout_indices = tuple ((overlap_clipped[i] .- first (r[i]) .+ 1 for i in eachindex (r)). .. )
38- view (aout, aout_indices... ) .= chunk_data
39- end
40- end
18+ AG. read (b. filename) do ds
19+ AG. getband (ds, b. band) do bh
20+ DiskArrays. readblock! (bh, aout, r... ) # ? what to do if size(aout) < r ranges ?, i.e. chunk reads!
4121 end
4222 end
43- end
44- function clip_overlap (range, max_size)
45- start = max (1 , range. start)
46- stop = min (max_size, range. stop)
47- return start <= stop ? start : stop
48- end
23+ end
4924
50- function DiskArrays. readblock! (b:: GDALBand , aout, r:: AbstractUnitRange... )
51- aout2 = similar (aout)
52- DiskArrays. readblock! (b, aout2, r)
53- aout .= aout2
54- end
55- function DiskArrays. readblock! (b:: GDALBand , aout, r:: Tuple{AbstractUnitRange, AbstractUnitRange} )
25+ function DiskArrays. readblock! (b:: GDALBand , aout:: Matrix , r:: Tuple{AbstractUnitRange, AbstractUnitRange} )
5626 DiskArrays. readblock! (b, aout, r... )
5727end
5828
@@ -63,14 +33,12 @@ function DiskArrays.writeblock!(b::GDALBand, ain, r::AbstractUnitRange...)
6333 end
6434 end
6535end
66-
67- function DiskArrays. writeblock! (b:: GDALBand , ain, r:: Tuple{AbstractUnitRange, AbstractUnitRange} )
68- AG. read (b. filename, flags= AG. OF_Update) do ds
69- AG. getband (ds, b. band) do bh
70- DiskArrays. writeblock! (bh, ain, r... )
71- end
72- end
36+ function DiskArrays. readblock! (b:: GDALBand , aout, r:: AbstractUnitRange... )
37+ aout2 = similar (aout)
38+ DiskArrays. readblock! (b, aout2, r)
39+ aout .= aout2
7340end
41+
7442struct GDALDataset
7543 filename:: String
7644 bandsize:: Tuple{Int,Int}
0 commit comments