diff --git a/R/api_mosaic.R b/R/api_mosaic.R index 856ec4be..85f77599 100644 --- a/R/api_mosaic.R +++ b/R/api_mosaic.R @@ -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) @@ -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), @@ -230,7 +237,7 @@ # 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), @@ -238,6 +245,8 @@ 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(