Extract coordinates from a georeferenced image.

extract_coords(georef_image, coords_df = NULL, col = "red")

Arguments

georef_image

A spatraster object representing the georeferenced image.

coords_df

An optional dataframe containing the coordinates of points previously extracted from the image. Default is NULL.

col

The colour of the points to be plotted on the image. Default is "red".

Value

A dataframe with ID and coordinates of the points extracted from the image.

Examples

if (FALSE) { # rlang::is_interactive()
# Load required packages
library(terra)
# Georeference the image using the created GCPs
# get the gcp coordinates
gcp_europe_coords <-
readRDS(system.file("vignettes/img/europe_gcp_georef_v2.RDS",
package = "crstools"))
# get the path to the image
img_path <- system.file("extdata/europe_map.jpeg", package = "crstools")
georef_path <-
georeference_img(image_obj = img_path,
gcp = gcp_europe_coords,
output_path = file.path(tempdir(), "europe_map_georef"))
# georeference the image using the GCPs
map_warp <- rast(georef_path)
# get the coordinates of the points
coords_df <- extract_coords(map_warp)
# if needed, extract additional points by supplying the coords_df argument
# and re run the function
coords_df <- extract_coords(map_warp, coords_df)
# dataframe with ID and coordinates of the points extracted from the image.
print(coords_df)
}