extract_coords.RdThis function allows to extract coordinates from a georeferenced image by clicking on points of interest. Every time a point is clicked, its latitude and longitude are captured, and a unique ID is assigned to it. If a dataframe of coordinates is supplied, the new points will be added to it, and the IDs will be numbered sequentially.
extract_coords(georef_image, coords_df = NULL, col = "red")A spatraster object representing the georeferenced image.
An optional dataframe containing the coordinates of points previously extracted from the image. It has to consist of 3 columns, named: "id", "longitude" and "latitude". Default is NULL.
The colour of the points to be plotted on the image. Default is "red".
A dataframe with ID and coordinates of the points extracted from the image.
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)
}