Skip to content

Commit 2e46779

Browse files
problems with bbox S1-RTC
1 parent d7a434f commit 2e46779

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

R/api_roi.R

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ NULL
9393
#' @returns \code{.roi_as_sf()}: \code{sf}.
9494
#' @noRd
9595
.roi_as_sf <- function(roi, default_crs = NULL, as_crs = NULL) {
96+
# is the roi defined by a shapefile
97+
if (is.character(roi) && file.exists(roi) && (tools::file_ext(roi) == "shp"))
98+
roi <- sf::st_read(roi)
99+
# convert R objects to sf object
96100
roi <- .roi_switch(
97101
roi = roi,
98102
sf = roi,

R/api_view.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@
116116
#' @param blue Band for blue color.
117117
#' @param class_cube Classified cube to be overlayed on top on image
118118
#' @param legend Named vector that associates labels to colors.
119+
#' @param opacity Opacity of segment fill
119120
#' @param palette Palette provided in the configuration file.
120121
#' @param seg_color Color for segments
121122
#' @param line_width Line width for segments
122-
#' @param fill_opacity Opacity of segment fill
123123
#' @param view_max_mb Maximum size of leaflet to be visualized
124124
#'
125125
#' @return A leaflet object.
@@ -511,6 +511,10 @@
511511
dates,
512512
palette,
513513
output_size) {
514+
# adjust for greyscale images
515+
# adjust palette
516+
if (palette == "Greys")
517+
palette <- grDevices::grey.colors(32, start = 0.05, end = 1.0)
514518
# obtain the raster objects for the dates chosen
515519
for (i in seq_along(dates)) {
516520
date <- as.Date(dates[[i]])

R/sits_bbox.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sits_bbox.raster_cube <- function(data, crs = "EPSG:4326", as_crs = NULL) {
6161
xmax = data[["xmax"]],
6262
ymin = data[["ymin"]],
6363
ymax = data[["ymax"]],
64-
crs = "EPSG:4236"
64+
crs = "EPSG:4326"
6565
)
6666
return(bbox)
6767
}

tests/testthat/test-cube.R

+43-6
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test_that("Creating cubes from BDC - CBERS-WFI-8D", {
160160
cube_nrows <- .tile_nrows(cbers_cube_8d)
161161
expect_true(.raster_nrows(r_obj) == cube_nrows)
162162
})
163-
test_that("Creating cubes from BDC - based on ROI with shapefile", {
163+
test_that("Creating cubes from BDC - based on ROI using sf obejct", {
164164
shp_file <- system.file(
165165
"extdata/shapefiles/mato_grosso/mt.shp",
166166
package = "sits"
@@ -218,6 +218,44 @@ test_that("Creating cubes from BDC - based on ROI with shapefile", {
218218
tile_011009 <- .cube_filter_tiles(modis_cube, "011009")
219219
expect_equal(nrow(tile_011009), 1)
220220

221+
})
222+
test_that("Creating cubes from BDC - based on ROI using shapefile", {
223+
shp_file <- system.file(
224+
"extdata/shapefiles/mato_grosso/mt.shp",
225+
package = "sits"
226+
)
227+
# create a raster cube file based on the information about the files
228+
modis_cube <- .try(
229+
{
230+
sits_cube(
231+
source = "BDC",
232+
collection = "MOD13Q1-6",
233+
bands = c("NDVI", "EVI"),
234+
roi = shp_file,
235+
start_date = "2018-09-01",
236+
end_date = "2019-08-29",
237+
progress = FALSE
238+
)
239+
},
240+
.default = NULL
241+
)
242+
testthat::skip_if(purrr::is_null(modis_cube),
243+
message = "BDC is not accessible"
244+
)
245+
expect_true(all(sits_bands(modis_cube) %in% c("NDVI", "EVI")))
246+
bbox <- sits_bbox(modis_cube, as_crs = "EPSG:4326")
247+
sf_mt <- sf::read_sf(shp_file)
248+
bbox_shp <- sf::st_bbox(sf_mt)
249+
expect_lt(bbox["xmin"], bbox_shp["xmin"])
250+
expect_lt(bbox["ymin"], bbox_shp["ymin"])
251+
expect_gt(bbox["xmax"], bbox_shp["xmax"])
252+
expect_gt(bbox["ymax"], bbox_shp["ymax"])
253+
intersects <- .cube_intersects(modis_cube, sf_mt)
254+
expect_true(all(intersects))
255+
256+
tile_011009 <- .cube_filter_tiles(modis_cube, "011009")
257+
expect_equal(nrow(tile_011009), 1)
258+
221259
})
222260
test_that("Creating cubes from BDC - invalid roi", {
223261
expect_error(
@@ -531,18 +569,17 @@ test_that("Creating Sentinel cubes from MPC with ROI", {
531569
expect_true(.raster_nrows(r_obj) == cube_nrows)
532570
})
533571
test_that("Creating Sentinel-1 RTC cubes from MPC", {
534-
roi <- sits_mgrs_to_roi("20LKP")
535572
cube_s1_rtc <- sits_cube(
536573
source = "MPC",
537574
collection = "SENTINEL-1-RTC",
538575
bands = c("VV", "VH"),
539576
orbit = "descending",
540-
roi = roi,
541-
start_date = "2023-03-01",
542-
end_date = "2023-09-30"
577+
tiles = c("24MUS", "24MVS"),
578+
start_date = "2021-03-01",
579+
end_date = "2021-09-30"
543580
)
544581
bbox <- sits_bbox(cube_s1_rtc)
545-
expect_true(grepl("18N", bbox[["crs"]]))
582+
expect_equal("EPSG:4326", bbox[["crs"]])
546583
expect_equal(381340, bbox[["xmin"]])
547584
expect_equal(701860, bbox[["xmax"]])
548585

0 commit comments

Comments
 (0)