Skip to content

Commit a0eeb40

Browse files
authored
fix too large buffer sizes on reduced reads (#145)
* fix too large buffer sizes on reduced reads * address review comments * bump patch version
1 parent 602858d commit a0eeb40

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
33
keywords = ["GDAL", "IO"]
44
license = "MIT"
55
desc = "A high level API for GDAL - Geospatial Data Abstraction Library"
6-
version = "0.5.1"
6+
version = "0.5.2"
77

88
[deps]
99
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/raster/rasterio.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function rasterio!(
7070
linespace::Integer = 0,
7171
bandspace::Integer = 0
7272
)
73-
rasterio!(dataset, buffer, bands, 0, 0, width(dataset), height(dataset),
73+
rasterio!(dataset, buffer, bands, 0, 0, size(buffer, 1), size(buffer, 2),
7474
access, pxspace, linespace, bandspace)
7575
return buffer
7676
end
@@ -156,7 +156,7 @@ function read(
156156
xsize::Integer,
157157
ysize::Integer
158158
)
159-
buffer = Array{pixeltype(rb)}(undef, width(rb), height(rb))
159+
buffer = Array{pixeltype(rb)}(undef, xsize, ysize)
160160
rasterio!(rb, buffer, xoffset, yoffset, xsize, ysize)
161161
return buffer
162162
end
@@ -307,7 +307,7 @@ function read(
307307
ysize::Integer
308308
)
309309
buffer = Array{pixeltype(getband(dataset, indices[1]))}(undef,
310-
width(dataset), height(dataset), length(indices))
310+
xsize, ysize, length(indices))
311311
rasterio!(dataset, buffer, indices, xsize, ysize, xoffset, yoffset)
312312
return buffer
313313
end
@@ -329,7 +329,7 @@ function read(
329329
cols::UnitRange{<:Integer}
330330
)
331331
buffer = Array{pixeltype(getband(dataset, indices[1]))}(undef,
332-
width(dataset), height(dataset), length(indices))
332+
length(cols), length(rows), length(indices))
333333
rasterio!(dataset, buffer, indices, rows, cols)
334334
return buffer
335335
end

test/test_rasterio.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ AG.read("ospy/data4/aster.img") do ds
146146
@test total / count 76.33891347095299
147147
@test total / (AG.height(ds) * AG.width(ds)) 47.55674749653172
148148
end
149+
150+
@testset "buffer size" begin
151+
@test size(AG.read(ds, 1, 0, 0, 20, 10)) === (20, 10)
152+
@test size(AG.read(ds, [1, 3], 0, 0, 20, 10)) === (20, 10, 2)
153+
@test size(AG.read(ds, 1, 1:10, 31:50)) === (20, 10)
154+
@test size(AG.read(ds, [1, 3], 1:10, 31:50)) === (20, 10, 2)
155+
band = AG.getband(ds, 1)
156+
@test size(AG.read( band, 0, 0, 20, 10)) === (20, 10)
157+
end
149158
end
150159

151160
# Untested

0 commit comments

Comments
 (0)