Skip to content

Commit

Permalink
Merge pull request #1279 from M3nin0/reg-bdc-tiles
Browse files Browse the repository at this point in the history
fix url parse
  • Loading branch information
gilbertocamara authored Jan 31, 2025
2 parents 085a63e + 606b699 commit 965bc4a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
10 changes: 8 additions & 2 deletions R/api_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -1473,13 +1473,19 @@ NULL
if (are_local_paths[[i]]) {
return(path)
}

path_prefix <- "/vsicurl/"
path <- stringr::str_replace(path, path_prefix, "")

url_parsed <- .url_parse(path)
url_parsed[["path"]] <- paste0(path_prefix, url_parsed[["path"]])

url_parsed[["query"]] <- utils::modifyList(
url_parsed[["query"]],
token_parsed[["query"]]
url_parsed[["query"]], token_parsed
)
# remove the additional chars added by httr
new_path <- gsub("^://", "", .url_build(url_parsed))
new_path <- paste0(path_prefix, new_path)
new_path
})
file_info[["token_expires"]] <- strptime(
Expand Down
44 changes: 34 additions & 10 deletions R/api_regularize.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,49 @@
tiles_filtered <- .grid_filter_tiles(
grid_system = grid_system, tiles = tiles, roi = roi
)
tiles_filtered_crs <- unique(tiles_filtered[["crs"]])

# save original cube classes
cube_class <- class(cube)
# bind all files
cube_fi <- dplyr::bind_rows(cube[["file_info"]])

# get reference files of each ``fid``
cube_fi_unique <- dplyr::distinct(
.data = cube_fi,
.data[["fid"]], .data[["xmin"]],
.data[["ymin"]], .data[["xmax"]],
.data[["ymax"]], .data[["crs"]]
)

# if unique crs pre-calculate bbox
fi_bbox <- NULL

if (length(tiles_filtered_crs) == 1) {
# extract bounding box from files
fi_bbox <- .bbox_as_sf(.bbox(
x = cube_fi_unique,
default_crs = .crs(cube),
by_feature = TRUE
), as_crs = tiles_filtered_crs)
}

# redistribute data into tiles
cube <- tiles_filtered |>
dplyr::rowwise() |>
dplyr::group_map(~{
# prepare a sf object representing the bbox of each image in
# file_info
cube_fi <- dplyr::bind_rows(cube[["file_info"]])
# extract bounding box from files
fi_bbox <- .bbox_as_sf(.bbox(
x = cube_fi,
default_crs = cube,
by_feature = TRUE
), as_crs = .x[["crs"]])
if (!.has(fi_bbox)) {
fi_bbox <- .bbox_as_sf(.bbox(
x = cube_fi_unique,
default_crs = .crs(cube),
by_feature = TRUE
), as_crs = .x[["crs"]])
}
# check intersection between files and tile
file_info <- cube_fi[.intersects(fi_bbox, .x), ]
fids_in_tile <- cube_fi_unique[.intersects(fi_bbox, .x), ]
# get fids in tile
file_info <- cube_fi[cube_fi[["fid"]] %in% fids_in_tile[["fid"]],]
# create cube!
.cube_create(
source = .tile_source(cube),
collection = .tile_collection(cube),
Expand Down

0 comments on commit 965bc4a

Please sign in to comment.