使用R包sf
,如何组合sfc
对象?例如,给定以下代码,将如何创建包含来自和的几何的单个sfc
对象?(应为2。)sfc12
sfc1
sfc2
length(sfc12)
library(sf)
pt1 = st_point(c(0,1))
pt2 = st_point(c(1,1))
sfc1 = st_sfc(pt1) # An sfc object
sfc2 = st_sfc(pt2) # Another sfc object
# sfc12 = ?
一些无效的方法:
sf_sfc(sfc1, sfc2)
# Error in vapply(lst, class, rep("", 3)) : values must be length 3,
# but FUN(X[[1]]) result is length 2
sfc1 + sfc2 # Seems to add the points coordinate-wise.
# Geometry set for 1 feature
# geometry type: POINT
# dimension: XY
# bbox: xmin: 1 ymin: 2 xmax: 1 ymax: 2
# epsg (SRID): NA
# proj4string: NA
# POINT(1 2)
rbind(sfc1, sfc2)
# [,1]
# sfc1 Numeric,2
# sfc2 Numeric,2