我不明白为什么下面代码块中的最后两个示例失败了
library(sf)
#> Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
p1 <- st_sfc(st_point(c(0, 0)))
p2 <- st_sfc(st_point(c(1, 1)))
p1[p2]
#> Geometry set for 0 features
#> Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
#> CRS: NA
p1[p2, op = st_intersects]
#> Error in `[.default`(p1, p2, op = st_intersects): incorrect number of dimensions
p1[p2, , op = st_intersects]
#> Error in `[.default`(p1, p2, , op = st_intersects): incorrect number of dimensions
当[.sfc
指定的默认操作恰好是st_intersects
时.
sf:::`[.sfc`
#> function (x, i, j, ..., op = st_intersects)
#> {
#> if (!missing(i) && (inherits(i, "sf") || inherits(i, "sfc") ||
#> inherits(i, "sfg")))
#> i = lengths(op(x, i, ...)) != 0
#> st_sfc(NextMethod(), crs = st_crs(x), precision = st_precision(x),
#> dim = if (length(x))
#> class(x[[1]])[1]
#> else "XY")
#> }
#> <bytecode: 0x00000255ad682df8>
#> <environment: namespace:sf>
创建于2024-01-21,包含reprex v2.0.2
你能帮帮我吗?对子设置sfc
对象时,我应该如何正确地指定op
参数?