st_rename_geometry: Rename geometry column of an sf object

View source: R/st_rename_geometry.R

st_rename_geometryR Documentation

Rename geometry column of an sf object

Description

[Superseded]

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 lists of sf objects.

Usage

st_rename_geometry(obj, geometry_name)

Arguments

obj

object of class sf

geometry_name

a single character string renaming the active list-column with simple feature geometries

Details

st_rename_geometry() is inspired by code found on gis.stackexchange and particularly useful to homogenize sf objects with differently named geometry columns or lists 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>))

Value

a sf object with renamed geometry list-column.

Examples

# 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")
  )
}

a-benini/sfhelpers documentation built on Aug. 28, 2024, 3:30 a.m.