Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

[new-feature] copying resample internals from GeoData #133

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/SimpleSDMLayers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ export WithinRadius, RandomSelection, SurfaceRangeEnvelope
include(joinpath("operations", "coarsen.jl"))
include(joinpath("operations", "sliding.jl"))
include(joinpath("operations", "mask.jl"))
include(joinpath("operations", "resample.jl"))
include(joinpath("operations", "rescale.jl"))
include(joinpath("operations", "mosaic.jl"))
export coarsen, slidingwindow, mask, rescale!, rescale, mosaic
export coarsen, slidingwindow, mask, rescale!, rescale, mosaic, resample

include(joinpath("recipes", "recipes.jl"))
export bivariate
Expand Down
34 changes: 34 additions & 0 deletions src/operations/resample.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function SimpleSDMLayers.resample(x)
GeoData.resample(x)
end

"""
Code from GeoData.jl

warp(A::AbstractGeoArray, flags::Dict)

function warp(A::AbstractGeoArray, flags::Dict)
odims = otherdims(A, (X, Y, Band))
if length(odims) > 0
# Handle dimensions other than X, Y, Band
slices = slice(A, odims)
warped = map(A -> _warp(A, flags), slices)
return combine(warped, odims)
else
return _warp(A, flags)
end
end
warp(st::AbstractGeoStack, flags::Dict) = map(A -> warp(A, flags), st)

function _warp(A::AbstractGeoArray, flags::Dict)
flagvect = reduce([flags...]; init=[]) do acc, (key, val)
append!(acc, String[_asflag(key), _stringvect(val)...])
end
AG.Dataset(A) do dataset
AG.gdalwarp([dataset], flagvect) do warped
_maybe_permute_from_gdal(read(GeoArray(warped)), dims(A))
end
end
end

"""