Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/e-sensing/sits into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Jan 22, 2025
2 parents b150569 + 1563c05 commit a02b0e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions R/api_mosaic.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@
tile = asset, band = .tile_bands(asset),
version = version, output_dir = output_dir
)
# Create a temporary output file name
# (this is required as in Windows machines, GDAL can't read and write
# using the same file)
out_file_base <- .file_crop_name(
tile = asset, band = .tile_bands(asset),
version = paste0(version, "mosaic"), output_dir = output_dir
)
# Resume feature
if (.raster_is_valid(out_file, output_dir = output_dir)) {
.check_recovery(out_file)
Expand Down Expand Up @@ -202,8 +209,8 @@
is_within <- .tile_within(asset, roi)
if (is_within) {
# Reproject tile for its crs
.gdal_reproject_image(
file = out_file, out_file = out_file,
out_file <- .gdal_reproject_image(
file = out_file, out_file = out_file_base,
crs = .as_crs(.tile_crs(asset)),
as_crs = .mosaic_crs(tile = asset, as_crs = crs),
miss_value = .miss_value(band_conf),
Expand All @@ -230,14 +237,16 @@
# Crop and reproject tile image
out_file <- .gdal_crop_image(
file = out_file,
out_file = out_file,
out_file = out_file_base,
roi_file = roi,
as_crs = .mosaic_crs(tile = asset, as_crs = crs),
miss_value = .miss_value(band_conf),
data_type = .data_type(band_conf),
multicores = 1,
overwrite = TRUE
)
# Move the generated file to use the correct name
file.rename(out_file_base, out_file)
# Update asset metadata
update_bbox <- if (.has(roi)) TRUE else FALSE
asset <- .tile_from_file(
Expand Down
2 changes: 2 additions & 0 deletions R/api_roi.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ NULL
if (.has(as_crs)) {
roi <- sf::st_transform(roi, crs = as_crs)
}
# Clean roi
roi <- .sf_clean(roi)
# Transform feature to multipolygons
roi <- if (.has(nrow(roi)) && nrow(roi) > 1) sf::st_union(roi) else roi
# Return roi
Expand Down

0 comments on commit a02b0e8

Please sign in to comment.