View source: R/extract_coords.R
| extract_coords | R Documentation |
This 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")
georef_image |
A spatraster object representing the georeferenced image. |
coords_df |
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. |
col |
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.
# Load required packages
library(terra)
# Georeference the image using the created GCPs
# get the gcp coordinates
gcp_europe_coords <-
readRDS(system.file("extdata/europe_gcp_georef.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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.