| bind_rows.SpatVector | R Documentation |
SpatVector, sf/sfc and data frames objects by rowBind any number of SpatVector, data frames and sf/sfc objects by row,
making a longer result. This is similar to do.call(rbind, dfs), but the
output will contain all columns that appear in any of the inputs.
bind_spat_rows(..., .id = NULL)
... |
Objects to combine. The first argument should be a |
.id |
The name of an optional identifier column. Provide a string to create an output column that identifies each input. The column will use names if available, otherwise it will use positions. |
A SpatVector of the same type as the first element of ....
rbind() method
Implementation of the dplyr::bind_rows() function for
SpatVector objects.
The first element of ... should be a SpatVector. Subsequent elements may
be SpatVector, sf/sfc objects or data frames:
If subsequent SpatVector/sf/sfc objects present a different CRS than the
first element, those elements would be reprojected to the CRS of the first
element with a message.
If any element of ... is a tibble/data frame the rows would be
cbinded with empty geometries with a message.
dplyr::bind_rows()
Other dplyr verbs that operate on pairs Spat*/data.frame:
bind_cols.SpatVector,
filter-joins.SpatVector,
mutate-joins.SpatVector
Other dplyr methods:
arrange.SpatVector(),
bind_cols.SpatVector,
count.SpatVector(),
distinct.SpatVector(),
filter-joins.SpatVector,
filter.Spat,
glimpse.Spat,
group-by.SpatVector,
mutate-joins.SpatVector,
mutate.Spat,
pull.Spat,
relocate.Spat,
rename.Spat,
rowwise.SpatVector(),
select.Spat,
slice.Spat,
summarise.SpatVector()
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 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")
# Use with sf
sfobj <- sf::st_as_sf(v2[1, ])
sfobj
bind_spat_rows(v1, sfobj)
# Would reproject with a message on different CRS
sfobj_3857 <- as_spatvector(sfobj) %>% project("EPSG:3857")
bind_spat_rows(v1, sfobj_3857)
# And with 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, ]))
# Or named list combined with .id
bind_spat_rows(list(
SpatVector = v1[1, ], sf = sfobj[1, ],
mtcars = mtcars[1, ]
), .id = "source")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.