Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Nov 25, 2023
1 parent 64d2750 commit d443e03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ext/RastersArchGDALExt/gdal_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ function RA.create(filename, ::Type{GDALsource}, T::Type, dims::DD.DimTuple;
)
T = Missings.nonmissingtype(T)
missingval = ismissing(missingval) ? RA._writeable_missing(T) : missingval
_create_with_driver(filename, dims, T, missingval; kw...) do A
verbose && _maybe_warn_south_up(dims, verbose, "Creating South-up. Use `reverse(x; dims=Y)` first to write conventional North-up")
_create_with_driver(filename, dims, T, missingval; kw...) do _
verbose && _maybe_warn_south_up(dims, verbose, "Creating a South-up raster. Use `reverse(x; dims=Y)` first to write conventional North-up")
nothing
end

return Raster(filename; source=GDALsource, name, lazy, dropband=!hasdim(dims, Band))
end

_maybe_warn_south_up(A, verbose, msg) =
verbose && lookup(A, Y) isa AbstractProjected && order(A, Y) isa ForwardOrdered && @warn msg
function _maybe_warn_south_up(A, verbose, msg)
verbose && lookup(A, Y) isa AbstractSampled && order(A, Y) isa ForwardOrdered && @warn msg
end

function RA._open(f, ::Type{GDALsource}, filename::AbstractString; write=false, kw...)
# Check the file actually exists because the GDAL error is unhelpful
Expand Down
3 changes: 2 additions & 1 deletion test/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))

A = [missing 7.0f0; 2.0f0 missing]
B = [1.0 0.4; 2.0 missing]
ga = Raster(A, (X, Y); missingval=missing)
ga = Raster(A, (X(1.0:1:2.0), Y(1.0:1:2.0)); missingval=missing)
st = RasterStack((a=A, b=B), (X, Y); missingval=(a=missing,b=missing))

pointvec = [(-20.0, 30.0),
Expand Down Expand Up @@ -52,6 +52,7 @@ gaMi = replace_missing(ga)
@test all(map(values(replace_missing(st, NaN32)), (a=[NaN32 7.0f0; 2.0f0 NaN32], b=[1.0 0.4; 2.0 NaN])) do x, y
all(x .=== y)
end)
ga
dNaN = replace_missing(ga, NaN32; filename="test.tif")
@test all(isequal.(dNaN, [NaN32 7.0f0; 2.0f0 NaN32]))
rm("test.tif")
Expand Down

0 comments on commit d443e03

Please sign in to comment.