Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,14 @@ st_sfc = function(..., crs = NA_crs_, precision = 0.0, check_ring_dir = FALSE, d
else
do.call(rbind, value)
attr(x, "points")[i, ] = repl
return(structure(x, n_empty = sum(is.na(attr(x, "points")[,1])))) # RETURNS
return(structure(x,
n_empty = sum(is.na(attr(x, "points")[,1])),
bbox = bbox.pointmatrix(attr(x, "points"))
)) # RETURNS
} else
x = x[] # realize
}
value = value[] # realize in case sfc_POINT while x is not
x = unclass(x) # becomes a list, but keeps attributes
ret = st_sfc(NextMethod(), recompute_bbox = TRUE)
structure(ret, n_empty = sum(sfc_is_empty(ret)))
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test_sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@ test_that("c.sfc n_empty returns sum of st_is_empty(sfg)", {
test_that("st_is_longlat warns on invalid bounding box", {
expect_warning(st_is_longlat(st_sfc(st_point(c(0,-95)), crs = 4326)))
})

test_that("value replacement works for sfc_POINT",{
pts1<-st_geometry(st_as_sf(data.frame(x=1:3,y=1:3), coords = c("x","y")))
pts2<-st_geometry(st_as_sf(data.frame(x=4:5,y=4:5), coords = c("x","y")))
expect_identical(replace(pts1[],2:3,pts2), replace(pts1[],2:3,pts2[]))
expect_identical(replace(pts1,2:3,pts2[])[], replace(pts1[],2:3,pts2[]))
expect_identical(replace(pts1,2:3,pts2)[], replace(pts1[],2:3,pts2[]))
expect_identical(st_bbox(replace(pts1,2:3,pts2)),
st_bbox(replace(pts1[],2:3,pts2[])))# check if bbox is correct without realization
})