|
2 | 2 | #' |
3 | 3 | #' @family HSI Co-registration |
4 | 4 | #' |
5 | | -#' @param x A [`SpatRaster`][terra::SpatRaster-class] to warp. Must have a |
6 | | -#' file source on disk. |
| 5 | +#' @param x A [`SpatRaster`][terra::SpatRaster-class] to warp. Must be a |
| 6 | +#' whole file on disk, not a window, layer subset or combination of files. |
7 | 7 | #' @param y A [`SpatRaster`][terra::SpatRaster-class] defining the output grid. |
8 | 8 | #' Output extent, resolution, and dimensions are taken from this raster. |
9 | 9 | #' @param gcp A [data.frame] or [tibble][tibble::tibble] of matched GCPs from |
@@ -129,6 +129,26 @@ hsi_coregister <- function( |
129 | 129 | ) |
130 | 130 | } |
131 | 131 |
|
| 132 | + # Source must be the whole file: GDAL warps the file, not a view of it |
| 133 | + x_sources <- terra::sources(x, bands = TRUE) |
| 134 | + |
| 135 | + x_file <- terra::rast(source_path) |
| 136 | + |
| 137 | + is_whole_file <- length(unique(x_sources$source)) == 1 && |
| 138 | + identical(as.integer(x_sources$bands), seq_len(terra::nlyr(x_file))) && |
| 139 | + identical(as.vector(terra::ext(x)), as.vector(terra::ext(x_file))) |
| 140 | + |
| 141 | + if (!is_whole_file) { |
| 142 | + cli::cli_abort( |
| 143 | + c( |
| 144 | + "{.arg x} is not a whole file on disk.", |
| 145 | + "i" = "Windows, layer subsets and combined rasters cannot be warped.", |
| 146 | + "i" = "Write it to disk first with {.code terra::writeRaster()}." |
| 147 | + ), |
| 148 | + class = "hsitools_error" |
| 149 | + ) |
| 150 | + } |
| 151 | + |
132 | 152 | # Temp VRT for GCP embedding |
133 | 153 | vrt_path <- withr::local_tempfile(fileext = ".vrt") |
134 | 154 |
|
|
0 commit comments