sf (version 0.3-4)

st_geometry: Get, set, or replace geometry from an sf object

Description

Get, set, or replace geometry from an sf object

Usage

# S3 method for sfc
st_geometry(obj, ...)

st_geometry(obj, ...)

# S3 method for sf st_geometry(obj, ...)

# S3 method for sfc st_geometry(obj, ...)

# S3 method for sfg st_geometry(obj, ...)

st_geometry(x) <- value

Arguments

obj
object of class sf or sfc
...
ignored
x
object of class data.frame
value
object of class sfc

Value

st_geometry returns an object of class sfc, a list-column with geometries st_geometry returns an object of class sfc. Assigning geometry to a data.frame creates an sf object, assigning it to an sf object replaces the geometry list-column.

Examples

Run this code
df = data.frame(a = 1:2)
sfc = st_sfc(st_point(c(3,4)), st_point(c(10,11)))
st_geometry(sfc)
st_geometry(df) <- sfc
class(df)
st_geometry(df)
st_geometry(df) <- sfc # replaces

Run the code above in your browser using DataCamp Workspace