@@ -143,29 +143,27 @@ st_sfc = function(..., crs = NA_crs_, precision = 0.0, check_ring_dir = FALSE, d
143143# ' @name sfc
144144# ' @param x object of class \code{sfc}
145145# ' @param i record selection. Might also be an \code{sfc}/\code{sf} object to work with the \code{op} argument
146- # ' @param j ignored
146+ # ' @param j ignored if `op` is specified
147147# ' @param op function, geometrical binary predicate function to apply when
148148# ' \code{i} is a \code{sf}/\code{sfc} object. Additional arguments can be
149149# ' specified using \code{...}, see examples.
150+ # ' @details if `x` has a `dim` attribute (i.e. is an `array` or `matrix`) then `op` cannot be used.
150151# ' @export
151152" [.sfc" = function (x , i , j , ... , op = st_intersects ) {
152- if (! missing(i ) && (inherits(i , " sf" ) || inherits(i , " sfc" ) || inherits(i , " sfg" )))
153- i = lengths(op(x , i , ... )) != 0
154153 precision = st_precision(x )
155154 crs = st_crs(x )
156155 dim = if (length(x )) class(x [[1 ]])[1 ] else " XY"
157- x = unclass(x )[i ] # now a list
158- st_sfc(x , crs = crs , precision = precision , dim = dim )
156+ if (! missing(i ) && (inherits(i , " sf" ) || inherits(i , " sfc" ) || inherits(i , " sfg" ))) {
157+ i = lengths(op(x , i , ... )) != 0
158+ st_sfc(unclass(x )[i ], crs = crs , precision = precision , dim = dim )
159+ } else
160+ st_sfc(NextMethod(), crs = crs , precision = precision , dim = dim )
159161}
160162
161-
162163# ' @export
163- # "[<-.sfc" = function (x, i, j, value) {
164- " [<-.sfc" = function (x , i , value ) {
164+ " [<-.sfc" = function (x , i , j , ... , value ) {
165165 if (is.null(value ) || inherits(value , " sfg" ))
166166 value = list (value )
167- x = unclass(x ) # becomes a list, but keeps attributes
168-
169167 ret = st_sfc(NextMethod(), recompute_bbox = TRUE )
170168 structure(ret , n_empty = sum(sfc_is_empty(ret )))
171169}
@@ -204,6 +202,8 @@ print.sfc = function(x, ..., n = 5L, what = "Geometry set for", append = "") {
204202 if (ne > 0 )
205203 cat(paste0(" (with " , ne , ifelse(ne > 1 , " geometries " , " geometry " ), " empty)" ))
206204 }
205+ if (! is.null(dim(x )))
206+ cat(paste0(" [dim: " , paste(dim(x ), collapse = " x " ), " ]" ))
207207 cat(" \n " )
208208 if (length(x )) {
209209 cat(paste0(" Geometry type: " , cls , " \n " ))
0 commit comments