Skip to content

Commit

Permalink
modifications handling c() and st_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Jun 29, 2023
1 parent 3f03184 commit 3ec76b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/bbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ bb_wrap = function(bb) {
}

bbox.pointmatrix = function(obj, ...) {
if (nrow(obj) == 0)
if (nrow(obj) == 0 || all(is.na(obj)))
bb_wrap(rep(NA_real_, 4))
else
bb_wrap(as.vector(t(apply(obj[,1:2,drop=FALSE], 2, range))))
bb_wrap(as.vector(t(apply(obj[,1:2,drop=FALSE], 2, range, na.rm = TRUE))))
}

bbox.Set = function(obj, ...) {
Expand Down
1 change: 1 addition & 0 deletions R/geom-measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ st_distance = function(x, y, ..., dist_fun, by_element = FALSE,
else
CPL_geos_dist(x, y, which, par)
}
d[is.nan(d)] = NA_real_
if (!is.null(u <- st_crs(x)$ud_unit))
units(d) = u
d
Expand Down
9 changes: 9 additions & 0 deletions R/sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,17 @@ c.sfc = function(..., recursive = FALSE) {
else
c(ucls, "sfc")

points_attr = sapply(lst, function(x) !is.null(attr(x, "points")))
if (any(points_attr) && !all(points_attr)) {
for (i in seq_along(lst))
lst[[i]] = lst[[i]][] # realize
points_attr = FALSE
}

ret = unlist(lapply(lst, unclass), recursive = FALSE)
attributes(ret) = attributes(lst[[1]]) # crs
if (all(points_attr))
attr(ret, "points") = do.call(rbind, lapply(lst, attr, "points"))
class(ret) = cls
attr(ret, "bbox") = compute_bbox(ret) # dispatch on class
attr(ret, "n_empty") = sum(sapply(lst, attr, which = "n_empty"))
Expand Down

0 comments on commit 3ec76b8

Please sign in to comment.