View source: R/georeference_img.R
| georeference_img | R Documentation |
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,
transform_method = c("auto", "poly_1", "poly_2", "poly_3", "tps")
)
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
|
output_path |
A character string giving the path (without extension)
used to name the output files: |
transform_method |
A character string specifying the transformation method to be used for warping the image. Options are "poly_1" (first order polynomial), "poly_2" (second order polynomial), "poly_3" (third order polynomial), "tps" (thin plate spline), or "auto" (the default, allowing GDAL to choose of a polynomial of the appropriate order based on the number of available GCP. Polynomials are best for standard maps directly captured from a publication (a first or second order polynomial is often sufficient), tps allows for scanning artefacts, but it is badly affected by any incorrect GCP. |
A character string representing the path to the newly created warped
TIFF image file (_warp.tif). This file contains the georeferenced image.
# 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_coords() 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(pattern = "georef_img_")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.