Skip to contents

Warp a source raster onto the target grid using matched ground control points via GDAL. Areas without source coverage are NA.

Usage

hsi_coregister(
  x,
  y,
  gcp,
  method = "bilinear",
  filename = "",
  overwrite = FALSE
)

Arguments

x

A SpatRaster to warp. Must have a file source on disk.

y

A SpatRaster defining the output grid. Output extent, resolution, and dimensions are taken from this raster.

gcp

A data.frame or tibble of matched GCPs from hsi_match_gcp(). Must contain columns source_x, source_y, target_x, target_y.

method

Character. Resampling method. One of "near", "bilinear", "cubic", "cubicspline", "lanczos". Default "bilinear".

filename

Character. Output filename. Default "" keeps result in memory.

overwrite

Logical. Overwrite existing file. Default FALSE.

Value

A SpatRaster aligned to the y grid.

Details

Uses sf::gdal_utils() internally. The source GCPs are embedded in a lightweight VRT (no data duplication), then GDAL warps onto the target grid with a first-order polynomial (affine) transformation. Band names from x are preserved in the output file.

Requires the sf package.

See also

hsi_match_gcp() for matching GCPs, hsi_check_gcp() for checking residuals first.

Other HSI Co-registration: hsi_check_gcp(), hsi_match_gcp()

Examples

if (FALSE) { # \dontrun{
matched <- hsi_match_gcp(swir_gcps, vnir_gcps)

x_coregistered <- hsi_coregister(
  x = swir,
  y = vnir,
  gcp = matched,
  filename = "SWIR_coregistered.tif"
)
} # }