Skip to content

Commit 642c493

Browse files
committed
when giving coord_sf(..., datum = NA)
1 parent 728d261 commit 642c493

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# version 0.5-3
22

3+
* allow for arith ops on empty `sfc` objects
4+
5+
* have `st_graticule` return an empty `sf` when argument `datum` is `NA`
6+
37
* export `as_Spatial`, to make it easer for packages to convert `sfc` objects without importing `sf`
48

59
* `st_distance` gains a parameter `by_element` to obtain pairwise distances; #437

R/arith.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,22 @@ conform = function(vec, m) {
7878

7979
#' @export
8080
Ops.sfc <- function(e1, e2) {
81+
82+
if (length(e1) == 0) # empty set
83+
return(e1)
84+
8185
if ((is.matrix(e2) && ncol(e2) == 2) || (is.numeric(e2) && length(e2) == 2))
8286
e1 = st_zm(e1) # drop z and/or m
87+
8388
if (!is.list(e2))
8489
e2 = list(e2)
90+
8591
ret = switch(.Generic,
8692
"*" = mapply(function(x, y) { x * unclass(y) }, e1, e2, SIMPLIFY = FALSE),
8793
"+" = mapply(function(x, y) { x + unclass(y) }, e1, e2, SIMPLIFY = FALSE),
8894
"-" = mapply(function(x, y) { x - unclass(y) }, e1, e2, SIMPLIFY = FALSE),
8995
"%%" = mapply(function(x, y) { x %% unclass(y) }, e1, e2, SIMPLIFY = FALSE),
9096
stop(paste("operation", .Generic, "not supported")))
97+
9198
st_sfc(ret, crs = NA_integer_, precision = attr(e1, "precision"))
9299
}

R/graticule.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ st_graticule = function(x = c(-180,-90,180,90), crs = st_crs(x),
7474
if (is.null(crs))
7575
crs = NA_crs_
7676

77-
if (is.null(datum) || is.na(datum))
77+
if (is.null(datum))
7878
datum = crs
7979

80+
if (is.na(datum))
81+
return(st_sf(geom = st_sfc()))
82+
8083
# Get the bounding box of the plotting space, in crs
8184
bb = if (inherits(x, "sf") || inherits(x, "sfc") || inherits(x, "sfg"))
8285
st_bbox(x)

0 commit comments

Comments
 (0)