Skip to content

Commit

Permalink
bugfix resample (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Dec 18, 2023
1 parent bed9992 commit 8a31eac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/RastersArchGDALExt/gdal_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ function RA.Raster(ds::AG.RasterDataset;
return dropband ? RA._drop_single_band(raster, lazy) : raster
end

RA.missingval(ds::AG.Dataset, args...) = RA.missingval(AG.RasterDataset(ds))
function RA.missingval(rasterds::AG.RasterDataset, args...)
# All bands have the same missingval in GDAL
band = AG.getband(rasterds.ds, 1)
Expand Down
2 changes: 2 additions & 0 deletions ext/RastersArchGDALExt/resample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ function resample(A::RasterStackOrArray;
return setcrs(resampled, crs)
end
end

_size_and_res_error() = throw(ArgumentError("Include only `size` or `res` keywords, not both"))
8 changes: 8 additions & 0 deletions test/resample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))

rm("resample.tif")

@testset "missingval propagates" begin
@test missingval(resample(cea; res=output_res, crs=output_crs, method)) == 0x00
end

@testset "snapped size and dim index match" begin
snaptarget = raster_output
snapped = resample(cea; to=snaptarget)
Expand Down Expand Up @@ -74,6 +78,10 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))
@test size(dims(resampled, (X, Y))) == (size(cea, X), size(cea, Y) * 2)
end

@testset "only size or res allowed not both" begin
@test_throws ArgumentError resample(cea; res=output_res, size=(1000, 1000))
end

@testset "only `size` kw sets the size" begin
res = step(span(cea, X)) / 2
resampled = resample(cea; size=(100, 200))
Expand Down

0 comments on commit 8a31eac

Please sign in to comment.