| getCoords | R Documentation | 
Function to get the coordinates in "x,y" format for a given set of points
getCoords(
  data,
  proj = NULL,
  x = "x",
  y = "y",
  z_fix = NULL,
  precision = 2,
  ...
)
data | 
 An object of class data.table or something coercible to it containing the coordinates needing conversion, or a SpatialPointsDataFrame.  | 
proj | 
 A crs object or character string representing the output
projection. Required unless   | 
x | 
 A character vector representing the column containing the 'x' coordinates.
Required if   | 
y | 
 A character vector representing the column containing the 'y' coordinates.
Required if   | 
z_fix | 
 A SpatRaster with the same origin and resolution as the
  | 
precision | 
 An integer representing the number of decimals to retain
in the x and y directions. For grid sizes with nice, round numbers precisions
can be low. This factor is controled by   | 
... | 
 Additional arguments to pass to   | 
A vector containing the requested coordinates in appropriate format in the same order as the input data.
# Generate a DEM
n <- 5
dem <- expand.grid(list(x = 1:(n * 100),
                        y = 1:(n * 100))) / 100
dem <- as.data.table(dem)
dem[, z := 250 * exp(-(x - n/2)^2) + 
      250 * exp(-(y - n/2)^2)]
dem <- rast(dem)
ext(dem) <- c(10000, 20000, 30000, 40000)
crs(dem) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
# Generate five random points that fall within the DEM
points <- data.table(x = runif(5, ext(dem)[1], ext(dem)[2]),
                     y = runif(5, ext(dem)[3], ext(dem)[4]))
# Get the coordinates
points$Cell <- getCoords(points, z_fix = dem)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.