This will extract using terra::crds, sf::st_coordinates and raster::coordinates. Other packages can create methods, as this is generic.

# S4 method for class 'ANY'
coordinates(obj, ...)

Arguments

obj

An object from which to extract the coordinates (e.g., sf, sp)

...

Ignored.

Value

A 2 column matrix of coordinates (x and y)

Examples

library(terra)
#> terra 1.8.54
caribou <- terra::vect(
  x = cbind(
    x = stats::runif(1e1, -50, 50),
    y = stats::runif(1e1, -50, 50)
  )
)
coordinates(caribou)
#>                 x          y
#>  [1,]  -0.2222611  -9.646188
#>  [2,] -21.0232755 -43.633854
#>  [3,]  23.2881987 -11.129869
#>  [4,]  27.2521511  47.554784
#>  [5,]  37.4600661 -21.010770
#>  [6,] -32.5059373  17.838043
#>  [7,] -46.5758667  23.531960
#>  [8,] -17.9614269 -30.404327
#>  [9,]  -9.7671762  48.053967
#> [10,] -30.4330165  24.152153