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.9.46
caribou <- terra::vect(
  x = cbind(
    x = stats::runif(1e1, -50, 50),
    y = stats::runif(1e1, -50, 50)
  )
)
coordinates(caribou)
#>                 x          y
#>  [1,] -41.9249862  37.460066
#>  [2,]  33.4333037 -32.505937
#>  [3,]  10.0760886 -46.575867
#>  [4,] -34.2791558 -17.961427
#>  [5,] -49.2600559  -9.767176
#>  [6,]  -3.3606503 -30.433017
#>  [7,]  -0.2222611  -9.646188
#>  [8,] -21.0232755 -43.633854
#>  [9,]  23.2881987 -11.129869
#> [10,]  27.2521511  47.554784