From e2a88e62989bacc75d6e11afeec4127a8a95177e Mon Sep 17 00:00:00 2001 From: michael catchen Date: Tue, 26 Oct 2021 11:36:25 -0400 Subject: [PATCH] :sparkles: new file for resampling --- src/SimpleSDMLayers.jl | 3 ++- src/operations/resample.jl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/operations/resample.jl diff --git a/src/SimpleSDMLayers.jl b/src/SimpleSDMLayers.jl index b880faff..d2c4f79a 100644 --- a/src/SimpleSDMLayers.jl +++ b/src/SimpleSDMLayers.jl @@ -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 diff --git a/src/operations/resample.jl b/src/operations/resample.jl new file mode 100644 index 00000000..f909fa18 --- /dev/null +++ b/src/operations/resample.jl @@ -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 + +""" \ No newline at end of file