Skip to content

Commit 3ec76b8

Browse files
committed
modifications handling c() and st_distance
1 parent 3f03184 commit 3ec76b8

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

R/bbox.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ bb_wrap = function(bb) {
1010
}
1111

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

1919
bbox.Set = function(obj, ...) {

R/geom-measures.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ st_distance = function(x, y, ..., dist_fun, by_element = FALSE,
181181
else
182182
CPL_geos_dist(x, y, which, par)
183183
}
184+
d[is.nan(d)] = NA_real_
184185
if (!is.null(u <- st_crs(x)$ud_unit))
185186
units(d) = u
186187
d

R/sfc.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,17 @@ c.sfc = function(..., recursive = FALSE) {
186186
else
187187
c(ucls, "sfc")
188188

189+
points_attr = sapply(lst, function(x) !is.null(attr(x, "points")))
190+
if (any(points_attr) && !all(points_attr)) {
191+
for (i in seq_along(lst))
192+
lst[[i]] = lst[[i]][] # realize
193+
points_attr = FALSE
194+
}
195+
189196
ret = unlist(lapply(lst, unclass), recursive = FALSE)
190197
attributes(ret) = attributes(lst[[1]]) # crs
198+
if (all(points_attr))
199+
attr(ret, "points") = do.call(rbind, lapply(lst, attr, "points"))
191200
class(ret) = cls
192201
attr(ret, "bbox") = compute_bbox(ret) # dispatch on class
193202
attr(ret, "n_empty") = sum(sapply(lst, attr, which = "n_empty"))

0 commit comments

Comments
 (0)