Skip to content

Commit ec47e06

Browse files
Revert "Revert "Adjust data type and properties to new computed indexes in sits_apply()""
1 parent 6ac57f9 commit ec47e06

6 files changed

+21
-30
lines changed

R/api_apply.R

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
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+
}
97100
# Evaluate expression here
98101
# Band and kernel evaluation
99102
values <- eval(

R/api_conf.R

+8-25
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@
428428
#' @keywords internal
429429
#' @noRd
430430
#' @return names associated to the chosen access key
431-
.conf_names <- function(key) {
431+
.conf_names <- function(...) {
432+
key <- c(...)
432433
res <- tryCatch(
433434
{
434435
names(sits_env$config[[key]])
@@ -928,41 +929,23 @@ NULL
928929
#' @param source Data source.
929930
#' @param collection Collection in the data source.
930931
#' @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, tile = NULL) {
937+
.conf_eo_band <- function(source, collection, band) {
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-
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-
}
942+
if (band %in% .conf_names("default_values", "eo_cube")) {
943+
return(.conf("default_values", "eo_cube", band))
957944
}
945+
return(.conf("default_values", "eo_cube", "default"))
958946
}
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)
947+
# Get band config value and return it
948+
.conf("sources", source, "collections", collection, "bands", band)
966949
}
967950
#' @title Config functions for derived_cube
968951
#' @noRd

R/api_cube.R

+6
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,12 @@ 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
11991205
block <- .raster_file_blocksize(.raster_open_rast(.tile_path(cube)))
12001206
cube_chunks <- slider::slide(cube, function(tile) {
12011207
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(c("sources", source, "collections"))
529+
collections <- .conf_names("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(sf::st_intersects(x, y, sparse = FALSE), 1, any)
75+
apply(suppressMessages(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(sf::st_within(x, y, sparse = FALSE), 1, any)
103+
apply(suppressMessages(sf::st_within(x, y, sparse = FALSE)), 1, any)
104104
}
105105
#' @title Spatial contains
106106
#' @noRd

R/api_tile.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,7 @@ 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]],
541-
tile = tile
540+
band = band[[1]]
542541
)
543542
}
544543
#' @export

0 commit comments

Comments
 (0)