Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sits_mosaic: fix mosaic in Windows OS #1268

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading