Skip to content

Commit

Permalink
Merge pull request #1268 from M3nin0/fix-mosaic-windows
Browse files Browse the repository at this point in the history
sits_mosaic: fix mosaic in Windows OS
  • Loading branch information
gilbertocamara authored Jan 17, 2025
2 parents 11ff526 + 44e6106 commit 1563c05
Showing 1 changed file with 12 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

0 comments on commit 1563c05

Please sign in to comment.