Skip to content

Commit

Permalink
update NEWS.md; add window_space tests
Browse files Browse the repository at this point in the history
  • Loading branch information
appelmar committed Feb 29, 2024
1 parent e1b19b4 commit 4fab616
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

* add `as.data.frame()` to easily convert data cubes to data frames
* add `predict.cube()` to predict pixel values based on models (lm, glm, caret, tidymodels, and similar)
* add `window_space()` to apply (focal) moving window kernels or aggregation functions
* `extract()` now combines extracted values with input geometries and attributes (if `merge = TRUE`)
* add support for imagery with spatial reference from geolocation arrays (including curvilinear grids)
* `stac_image_collection()` now accepts STACItemCollection objects directly and should be more robust
* Windows build uses pkg-config if available


# gdalcubes 0.6.4 (2023-04-14)
Expand Down
19 changes: 9 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.71 for gdalcubes 0.6.4.
# Generated by GNU Autoconf 2.71 for gdalcubes 0.6.9999.
#
# Report bugs to <marius.appel@hs-bochum.de>.
#
Expand Down Expand Up @@ -610,8 +610,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='gdalcubes'
PACKAGE_TARNAME='gdalcubes'
PACKAGE_VERSION='0.6.4'
PACKAGE_STRING='gdalcubes 0.6.4'
PACKAGE_VERSION='0.6.9999'
PACKAGE_STRING='gdalcubes 0.6.9999'
PACKAGE_BUGREPORT='marius.appel@hs-bochum.de'
PACKAGE_URL=''

Expand Down Expand Up @@ -1279,7 +1279,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures gdalcubes 0.6.4 to adapt to many kinds of systems.
\`configure' configures gdalcubes 0.6.9999 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1341,7 +1341,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of gdalcubes 0.6.4:";;
short | recursive ) echo "Configuration of gdalcubes 0.6.9999:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1439,7 +1439,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
gdalcubes configure 0.6.4
gdalcubes configure 0.6.9999
generated by GNU Autoconf 2.71
Copyright (C) 2021 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1595,7 +1595,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by gdalcubes $as_me 0.6.4, which was
It was created by gdalcubes $as_me 0.6.9999, which was
generated by GNU Autoconf 2.71. Invocation command line was
$ $0$ac_configure_args_raw
Expand Down Expand Up @@ -4382,7 +4382,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by gdalcubes $as_me 0.6.4, which was
This file was extended by gdalcubes $as_me 0.6.9999, which was
generated by GNU Autoconf 2.71. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -4437,7 +4437,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
gdalcubes config.status 0.6.4
gdalcubes config.status 0.6.9999
configured by $0, generated by GNU Autoconf 2.71,
with options \\"\$ac_cs_config\\"
Expand Down Expand Up @@ -4998,4 +4998,3 @@ printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2
fi
49 changes: 49 additions & 0 deletions inst/tinytest/test_window_space.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
library(gdalcubes)
v = cube_view(srs = "EPSG:4326", extent = list(left = 5, right = 15, bottom = 48, top = 58,
t0 = "2021-01-01", t1 = "2021-12-31"), dt = "P365D",
dx = 1, dy = 1)
v

gdalcubes:::.raster_cube_dummy(v, 1, 1.0) |>
window_space("max(band1)","min(band1)", window = c(5,5)) |>
as_array() -> x

expect_true(all(x == 1))



gdalcubes:::.raster_cube_dummy(v, 1, 1.0) |>
window_space("count(band1)", window = c(3,3)) |>
as_array() -> x
Xtrue = matrix(9, 10,10)
Xtrue[c(1,10),] = Xtrue[,c(1,10)] = 6
Xtrue[1,1] = Xtrue[1,10] = Xtrue[10,1] = Xtrue[10,10] = 4
expect_true(all(x[1,1,,] == Xtrue))


K = matrix(1, 3,3)

gdalcubes:::.raster_cube_dummy(v, 1, 1.0) |>
window_space(kernel = K, pad = 0) |>
as_array() -> x
expect_true(all(x[1,1,,] == Xtrue))

gdalcubes:::.raster_cube_dummy(v, 1, 1.0) |>
window_space(kernel = K, pad = "REFLECT") |>
as_array() -> x
expect_true(all(x == 9))


gdalcubes:::.raster_cube_dummy(v, 1, 1.0) |>
window_space(kernel = K, pad = "REPLICATE") |>
as_array() -> x
expect_true(all(x == 9))




gdalcubes:::.raster_cube_dummy(v, 1, 1.0, chunking = c(1,3,2)) |>
window_space(kernel = K, pad = "REPLICATE") |>
as_array() -> x
expect_true(all(x == 9))

10 changes: 10 additions & 0 deletions src/gdalcubes/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ void utils::env::unset_all() {
_vars.clear();
}


std::string utils::env::get(std::string var_name, std::string default_value) {
std::string out = default_value;
char* r = getenv(var_name.c_str());
if (r) {
out = r;
}
return out;
}

std::string utils::env::to_string() {
std::string out;
out = "{";
Expand Down
1 change: 1 addition & 0 deletions src/gdalcubes/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class utils {
void set(std::map<std::string, std::string> vars);
void unset(std::set<std::string> var_names);
void unset_all();
std::string get(std::string var_name, std::string default_value = "");

// Convert environment variable map to a JSON string
std::string to_string();
Expand Down
12 changes: 10 additions & 2 deletions src/gdalcubes/src/warp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,17 @@ GDALDataset *gdalwarp_client::warp_complex(GDALDataset *in, std::string s_srs, s
psWarpOptions->pfnProgress = GDALDummyProgress;

// see https://github.com/OSGeo/gdal/blob/64cf9b4e889c93e34177237665fe842186d1f581/alg/gdaltransformer.cpp#L1274C5-L1275C67
GDALGenImgProjTransformInfo *psInfo = static_cast<GDALGenImgProjTransformInfo *>(GDALCreateGenImgProjTransformer(in, s_srs.c_str(), out, NULL, TRUE, 0.0, 1 ));

CPLStringList trnsfrm_opts;
// TODO: Do we need to check if t_srs and/or s_src are empty?
trnsfrm_opts.AddNameValue("SRC_SRS", s_srs.c_str());
trnsfrm_opts.AddNameValue("GEOLOC_USE_TEMP_DATASETS", "NO");
GDALGenImgProjTransformInfo *psInfo = static_cast<GDALGenImgProjTransformInfo *>(GDALCreateGenImgProjTransformer2(in, out, trnsfrm_opts.List()));
//GDALGenImgProjTransformInfo *psInfo = static_cast<GDALGenImgProjTransformInfo *>(GDALCreateGenImgProjTransformer(in, s_srs.c_str(), out, NULL, TRUE, 0.0, 1 ));

// TODO DO we need to check if psInfo is NULL?


// Overwrite reprojection transform if needed, to benefit from cache
OGRSpatialReference srs_in;
srs_in.SetFromUserInput(s_srs.c_str());
Expand Down Expand Up @@ -648,7 +656,7 @@ GDALDataset *gdalwarp_client::warp_complex(GDALDataset *in, std::string s_srs, s
}

static_cast<GDALGenImgProjTransformInfo *>(psWarpOptions->pTransformerArg)->pReprojectArg = tmparg; // safe release
GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
GDALDestroyWarpOptions(psWarpOptions);

CPLFree(wkt_out);
Expand Down

0 comments on commit 4fab616

Please sign in to comment.