Skip to content

Commit 6ac57f9

Browse files
Merge pull request #1070 from e-sensing/revert-1066-feat/appy_prop
Revert "Adjust data type and properties to new computed indexes in `sits_apply()`"
2 parents 472c1a8 + 538a1b7 commit 6ac57f9

6 files changed

+30
-21
lines changed

R/api_apply.R

-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@
9494
values <- .apply_data_read(
9595
tile = feature, block = block, in_bands = in_bands
9696
)
97-
if (all(is.na(values))) {
98-
return(NULL)
99-
}
10097
# Evaluate expression here
10198
# Band and kernel evaluation
10299
values <- eval(

R/api_conf.R

+25-8
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@
428428
#' @keywords internal
429429
#' @noRd
430430
#' @return names associated to the chosen access key
431-
.conf_names <- function(...) {
432-
key <- c(...)
431+
.conf_names <- function(key) {
433432
res <- tryCatch(
434433
{
435434
names(sits_env$config[[key]])
@@ -929,23 +928,41 @@ NULL
929928
#' @param source Data source.
930929
#' @param collection Collection in the data source.
931930
#' @param band Band name
931+
#' @param tile Tile
932932
#' @details
933933
#' If the band is not found, a default value will be returned from config.
934934
#' If neither source nor collection entries are found in configuration file,
935935
#' an error is thrown.
936936
#' @returns A value in config.
937-
.conf_eo_band <- function(source, collection, band) {
937+
.conf_eo_band <- function(source, collection, band, tile = NULL) {
938938
# Format band name
939939
band <- .band_eo(band)
940940
# Return a default value if band does not exists in config
941941
if (!.conf_eo_band_exists(source, collection, band)) {
942-
if (band %in% .conf_names("default_values", "eo_cube")) {
943-
return(.conf("default_values", "eo_cube", band))
942+
data_type <- "INT2S"
943+
# does the file exist?
944+
if (!purrr::is_null(tile)) {
945+
band_path <- .tile_path(tile, band)
946+
if (!purrr::is_null(band_path)) {
947+
rast <- terra::rast(band_path)
948+
data_type <- terra::datatype(rast)
949+
conf_band <- .conf("default_vales", data_type)
950+
} else {
951+
# file does not exist
952+
if (!.has(.conf("default_vales", band)))
953+
conf_band <- .conf("default_vales", band)
954+
else
955+
conf_band <- .conf("default_vales", "INT4S")
956+
}
944957
}
945-
return(.conf("default_values", "eo_cube", "default"))
946958
}
947-
# Get band config value and return it
948-
.conf("sources", source, "collections", collection, "bands", band)
959+
else {
960+
# Get band config value and return it
961+
conf_band <- .conf("sources", source,
962+
"collections", collection,
963+
"bands", band)
964+
}
965+
return(conf_band)
949966
}
950967
#' @title Config functions for derived_cube
951968
#' @noRd

R/api_cube.R

-6
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,6 @@ NULL
11961196
}
11971197

11981198
.cube_split_chunks_samples <- function(cube, samples_sf) {
1199-
# Hold s2 status
1200-
s2_status <- sf::sf_use_s2()
1201-
suppressMessages(sf::sf_use_s2(FALSE))
1202-
# Back to original status on exit
1203-
on.exit(suppressMessages(sf::sf_use_s2(s2_status)))
1204-
# Get block size of raster file
12051199
block <- .raster_file_blocksize(.raster_open_rast(.tile_path(cube)))
12061200
cube_chunks <- slider::slide(cube, function(tile) {
12071201
chunks <- .tile_chunks_create(

R/api_source.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ NULL
526526
# check source
527527
.source_check(source = source)
528528
# get collections from source
529-
collections <- .conf_names("sources", source, "collections")
529+
collections <- .conf_names(c("sources", source, "collections"))
530530
return(collections)
531531
}
532532

R/api_space_time_operations.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
.intersects <- function(x, y) {
7373
as_crs <- sf::st_crs(x)
7474
y <- sf::st_transform(y, crs = as_crs)
75-
apply(suppressMessages(sf::st_intersects(x, y, sparse = FALSE)), 1, any)
75+
apply(sf::st_intersects(x, y, sparse = FALSE), 1, any)
7676
}
7777
#' @title Spatial within
7878
#' @noRd
@@ -100,7 +100,7 @@
100100
.within <- function(x, y) {
101101
as_crs <- sf::st_crs(x)
102102
y <- sf::st_transform(y, crs = as_crs)
103-
apply(suppressMessages(sf::st_within(x, y, sparse = FALSE)), 1, any)
103+
apply(sf::st_within(x, y, sparse = FALSE), 1, any)
104104
}
105105
#' @title Spatial contains
106106
#' @noRd

R/api_tile.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ NULL
537537
.tile_band_conf.eo_cube <- function(tile, band) {
538538
.conf_eo_band(
539539
source = .tile_source(tile), collection = .tile_collection(tile),
540-
band = band[[1]]
540+
band = band[[1]],
541+
tile = tile
541542
)
542543
}
543544
#' @export

0 commit comments

Comments
 (0)