Construct the projection matrices

Construct prediction locations:

grid <- rast(map, nrows = 100, ncols = 100)
# transform grid to a sf points object
dp <- grid |> 
  crds() |> 
  as.data.frame() |> 
  st_as_sf(coords = c("x", "y"), crs = st_crs(map))
# indices points within the map
indicespointswithin <- which(st_intersects(dp, map, sparse = FALSE))
# points within the map
dp <- st_filter(dp, map)
coop <- st_coordinates(dp)