View source: R/st_rename_geometry.R
st_rename_geometry | R Documentation |
With sf
package version >= 1.0-6 st_set_geometry
and
st_geometry<-
have become handy tools for renaming the
active geometry columns of sf
objects. st_set_geometry
now
offers the same functionality as st_rename_geometry
(s. examples), and
it is faster, which is advantageous when working on large list
s of
sf
objects.
st_rename_geometry(obj, geometry_name)
obj |
object of class |
geometry_name |
a single character string renaming the active list-column with simple feature geometries |
st_rename_geometry()
is inspired by code found on
gis.stackexchange
and particularly useful to homogenize sf
objects with differently
named geometry columns or list
s of such before binding them to a single
sf
object by
rbind
(bind
)
do.call(rbind, <list_of_sf>)
sf::st_as_sf(data.table::rbindlist(<list_of_sf>))
a sf
object with renamed geometry list-column.
# current active list-column with simple feature geometries:
attr(poly_1, "sf_column")
st_rename_geometry(poly_1, "renamed_geometry")
library(sf)
if(packageVersion("sf") >= '1.0.6'){
all.equal(
st_rename_geometry(poly_1, "renamed_geometry"),
st_set_geometry(poly_1, "renamed_geometry")
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.