@@ -124,31 +124,28 @@ st_geometry.sfg = function(obj, ...) st_sfc(obj)
124
124
`st_geometry<-` = function (x , value ) UseMethod(" st_geometry<-" )
125
125
126
126
# ' @export
127
- `st_geometry<-.data.frame` = function (x , value ) {
128
- stopifnot(inherits(value , " sfc" ) || is.character(value ))
129
- if (inherits(value , " sfc" ))
130
- stopifnot(nrow(x ) == length(value ))
131
- if (is.character(value ))
132
- st_sf(x , sf_column_name = value )
133
- else {
134
- a = vapply(x , function (v ) inherits(v , " sfc" ), TRUE )
135
- if (any(a )) {
136
- w = which(a )
137
- sf_col = attr(x , " sf_column" )
138
- if (! is.null(sf_col ))
139
- x [[ sf_col ]] = value
140
- else {
141
- if (length(w ) > 1 )
142
- warning(" overwriting first sfc column" )
143
- x [[ which(a )[1L ] ]] = value
144
- }
145
- } else
146
- x $ geometry = value
147
- st_sf(x )
148
- }
127
+ `st_geometry<-.data.frame` <- function (x , value ) {
128
+ stopifnot(inherits(value , " sfc" ) || is.character(value ))
129
+ if (inherits(value , " sfc" ))
130
+ stopifnot(nrow(x ) == length(value ))
131
+ if (is.character(value ))
132
+ st_sf(x , sf_column_name = value )
133
+ else {
134
+ a = vapply(x , function (v ) inherits(v , " sfc" ), TRUE )
135
+ sf_col = attr(x , " sf_column" )
136
+ if (! is.null(sf_col ))
137
+ x [[sf_col ]] = value
138
+ else if (any(a )) {
139
+ w = which(a )
140
+ if (length(w ) > 1 )
141
+ warning(" overwriting first sfc column" )
142
+ x [[which(a )[1L ]]] = value
143
+ }
144
+ else x $ geometry = value
145
+ st_sf(x )
146
+ }
149
147
}
150
148
151
-
152
149
# ' @export
153
150
`st_geometry<-.sf` = function (x , value ) {
154
151
if (! is.null(value )) {
@@ -457,6 +454,7 @@ merge.sf = function(x, y, ...) {
457
454
class(ret ) = setdiff(class(ret ), " sf" )
458
455
g = ret [[sf_column ]] # may have NULL values in it
459
456
ret [[sf_column ]] = NULL
457
+ attr(ret , " sf_column" ) <- sf_column
460
458
st_set_geometry(ret , st_sfc(g )) # FIXME: set agr
461
459
}
462
460
0 commit comments