library(terra)
v <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
v1 <- v[1, "cpro"]
v2 <- v[3:5, c("name", "iso2")]
# You can supply individual SpatVector objects as arguments.
bind_spat_rows(v1, v2)
# When you supply a column name with the `.id` argument, a new column is
# created to link each row to its original data frame.
bind_spat_rows(v1, v2, .id = "id")
# \donttest{
# Use with sf objects.
sfobj <- sf::st_as_sf(v2[1, ])
sfobj
bind_spat_rows(v1, sfobj)
# Reproject with a message when the CRS differs.
sfobj_3857 <- as_spatvector(sfobj) |> project("EPSG:3857")
bind_spat_rows(v1, sfobj_3857)
# Bind data frames with a message.
data("mtcars")
bind_spat_rows(v1, sfobj, mtcars, .id = "id2")
# Use lists
bind_spat_rows(list(v1[1, ], sfobj[1:2, ]))
# Use a named list with `.id`.
bind_spat_rows(list(
SpatVector = v1[1, ], sf = sfobj[1, ],
mtcars = mtcars[1, ]
), .id = "source")
# }
Run the code above in your browser using DataLab