get_pts_coords: Extract geographic coordinates from pixel coordinates

View source: R/get_pts_coords.R

get_pts_coordsR Documentation

Extract geographic coordinates from pixel coordinates

Description

Transform target point pixel coordinates into longitude/latitude coordinates using a set of Ground Control Points (GCPs). This function performs direct point-wise coordinate transformation without warping a raster.

Usage

get_pts_coords(gcp, target_pts, transform_method = "auto", lambda = 0)

Arguments

gcp

A data frame containing the Ground Control Points (GCPs). This dataframe can be produced with the choose_gcp() and find_gcp_coords() functions. 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).

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

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

target_pts

A data frame containing the target points to transform. This dataframe must contain the following columns (any other column, such as an identifier for each point, is kept in the output):

  • x or cx: The x-coordinate of the point (in pixel space).

  • y or cy: The y-coordinate of the point (in pixel space).

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, automatically selecting a polynomial order based on the number of GCPs available).

lambda

Numeric smoothing parameter used for thin plate spline transformations (transform_method = "tps"). The default, 0, interpolates exactly through the GCPs, matching the GDAL thin plate spline used by georeference_img(). Larger values introduce smoothing (the spline no longer passes exactly through the GCPs), which may improve robustness when GCPs contain noise or digitizing errors. As pixel coordinates are rescaled by the extent of the GCPs before fitting, the amount of smoothing for a given lambda does not depend on the resolution of the image.

Details

Polynomial transformations are implemented using native linear models, while thin plate spline transformations are implemented using fields::Tps(). For thin plate splines, the x and y pixel coordinates are rescaled by the same factor, so that distances between points are proportional to distances in pixels, as in the GDAL thin plate spline used by georeference_img().

Note that, when using tps as a method, fields::Tps() might print "Grid searches over lambda (nugget and sill variances) with minima at the endpoints". This is benign: fields::Tps() always searches for the best smoothing parameter and reports when the best value is at the edge of its search range, but the fit uses the value given in lambda.

Value

A data frame containing:

  • All the columns of target_pts (including the pixel coordinates).

  • longitude: Estimated longitude.

  • latitude: Estimated latitude.

Examples

pts_df <- readRDS(system.file(
  "extdata/europe_gcp_georef.RDS",
  package = "crstools"
))
target_df <- data.frame(pt_id = 1:2, x = c(477, 2014), y = c(554, 1311))
get_pts_coords(pts_df, target_df)


crstools documentation built on Nov. 28, 2026, 1:08 a.m.