This function warps a given image using a set of Ground Control Points (GCPs) to create a georeferenced version of the image. The function uses GDAL tools to first translate the image into a georeferenced TIFF format and then applies a warp operation to reproject the image into a spatial reference system (EPSG:4326). The warped image is saved as a new file with the suffix _warp.tif.

georeference_img(image_obj, gcp, output_path = NULL)

Arguments

image_obj

A character string specifying the file path to the input image (JPEG format). The function reads this image and applies the GCPs for georeferencing.

gcp

A data frame containing the Ground Control Points (GCPs). This dataframe can be produced with the draw_gcp_points function. This data frame should have the following columns:

  • id: An identifier for each GCP (numeric).

  • x: The x-coordinate of the GCP (in pixel space).

  • y: The y-coordinate of the GCP (in pixel space).

  • lon: The longitude of the GCP (georeferenced).

  • lat: The latitude of the GCP (georeferenced).

output_path

A character string representing the file path to the input image. (_warp.tif) will be appended to it.

Value

A character string representing the path to the newly created warped TIFF image file (_warp.tif). This file contains the georeferenced image.

Examples

if (FALSE) { # rlang::is_interactive()
# get the path to an example image included in the package
img_path <- system.file("extdata/europe_map.jpeg", package = "crstools")
# load a set of GCPs (or we could create them using the choose_gcp()
# and find_gcp() functions)
gcp_df <- readRDS(system.file(
  "extdata/europe_gcp_georef.RDS",
  package = "crstools"
))
#' # Assuming you have a set of GCPs in gcp_df and an image file "image.jpg"
warped_img <- georeference_img(
  image_obj = img_path, gcp = gcp_df,
  output_path = tempfile(
    patter = "georef_img_",
    tmpdir = tempdir(),
    fileext = ".tif"
  )
)
}