diff --git a/NAMESPACE b/NAMESPACE index fc77e6541..0cd278102 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -559,6 +559,7 @@ importFrom(units,drop_units) importFrom(units,make_unit_label) importFrom(units,set_units) importFrom(utils,compareVersion) +importFrom(utils,globalVariables) importFrom(utils,head) importFrom(utils,object.size) importFrom(utils,packageVersion) diff --git a/R/RcppExports.R b/R/RcppExports.R index 1d95c7b85..c5e8b4254 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -403,5 +403,5 @@ CPL_get_m_range <- function(sf, depth) { # Register entry points for exported C++ functions methods::setLoadAction(function(ns) { - .Call('_sf_RcppExport_registerCCallable', PACKAGE = 'sf') + .Call(`_sf_RcppExport_registerCCallable`) }) diff --git a/R/init.R b/R/init.R index 478801f89..9bcc1b071 100644 --- a/R/init.R +++ b/R/init.R @@ -1,4 +1,4 @@ -#' @importFrom utils head object.size str tail packageVersion compareVersion +#' @importFrom utils head object.size str tail packageVersion compareVersion globalVariables #' @importFrom stats aggregate dist na.omit rbinom runif setNames #' @importFrom tools file_ext file_path_sans_ext #' @importFrom methods as new slot slotNames "slot<-" diff --git a/R/sample.R b/R/sample.R index cda086abf..9cd74d8c6 100644 --- a/R/sample.R +++ b/R/sample.R @@ -52,13 +52,13 @@ st_sample = function(x, size, ...) UseMethod("st_sample") #' if (sf_extSoftVersion()["proj.4"] >= "4.9.0") #' plot(p <- st_sample(x, 1000), add = TRUE) #' if (require(lwgeom, quietly = TRUE)) { # for st_segmentize() -#' x2 = st_transform(st_segmentize(x, 1e4), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) -#' g = st_transform(st_graticule(), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) -#' plot(x2, graticule = g) -#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0") { -#' p2 = st_transform(p, st_crs("+proj=ortho +lat_0=30 +lon_0=45")) -#' plot(p2, add = TRUE) -#' } +#' x2 = st_transform(st_segmentize(x, 1e4), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) +#' g = st_transform(st_graticule(), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) +#' plot(x2, graticule = g) +#' if (sf_extSoftVersion()["proj.4"] >= "4.9.0") { +#' p2 = st_transform(p, st_crs("+proj=ortho +lat_0=30 +lon_0=45")) +#' plot(p2, add = TRUE) +#' } #' } #' x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,10),c(0,90),c(0,0))))) # NOT long/lat: #' plot(x) @@ -90,9 +90,9 @@ st_sample = function(x, size, ...) UseMethod("st_sample") #' plot(st_sample(ls, 80)) #' # spatstat example: #' if (require(spatstat.random)) { -#' x <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 0))))) -#' # for spatstat.random::rThomas(), set type = "Thomas": -#' pts <- st_sample(x, kappa = 1, mu = 10, scale = 0.1, type = "Thomas") +#' x <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 0))))) +#' # for spatstat.random::rThomas(), set type = "Thomas": +#' pts <- st_sample(x, kappa = 1, mu = 10, scale = 0.1, type = "Thomas") #' } #' @export #' @name st_sample @@ -164,9 +164,13 @@ st_poly_sample = function(x, size, ..., type = "random", global = FALSE bb = st_bbox(x) if (isTRUE(st_is_longlat(x))) { - if (sf_use_s2()) - bb = st_bbox(st_segmentize(st_as_sfc(bb), + if (sf_use_s2()) { # if FALSE, the user wants the coord ranges to be the bbox + if (!requireNamespace("lwgeom", quietly = TRUE)) + warning("coordinate ranges not computed along great circles; install package lwgeom to get rid of this warning") + else + bb = st_bbox(st_segmentize(st_as_sfc(bb), units::set_units(1, "degree", mode = "standard"))) # get coordinate range on S2 + } R = s2::s2_earth_radius_meters() toRad = pi / 180 h1 = sin(bb["ymax"] * toRad) diff --git a/R/tidyverse.R b/R/tidyverse.R index c5073664b..881c91a14 100644 --- a/R/tidyverse.R +++ b/R/tidyverse.R @@ -460,6 +460,7 @@ pivot_longer.sf <- function (data, cols, names_to = "name", names_prefix = NULL, st_as_sf(out, sf_column_name = sf_column_name) } +globalVariables(c("name", "value")) # https://github.com/r-spatial/sf/issues/1915 #' @name tidyverse #' @export diff --git a/man/st_sample.Rd b/man/st_sample.Rd index 3fc76907b..37164b391 100644 --- a/man/st_sample.Rd +++ b/man/st_sample.Rd @@ -86,13 +86,13 @@ plot(x, axes = TRUE, graticule = TRUE) if (sf_extSoftVersion()["proj.4"] >= "4.9.0") plot(p <- st_sample(x, 1000), add = TRUE) if (require(lwgeom, quietly = TRUE)) { # for st_segmentize() -x2 = st_transform(st_segmentize(x, 1e4), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) -g = st_transform(st_graticule(), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) -plot(x2, graticule = g) -if (sf_extSoftVersion()["proj.4"] >= "4.9.0") { - p2 = st_transform(p, st_crs("+proj=ortho +lat_0=30 +lon_0=45")) - plot(p2, add = TRUE) -} + x2 = st_transform(st_segmentize(x, 1e4), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) + g = st_transform(st_graticule(), st_crs("+proj=ortho +lat_0=30 +lon_0=45")) + plot(x2, graticule = g) + if (sf_extSoftVersion()["proj.4"] >= "4.9.0") { + p2 = st_transform(p, st_crs("+proj=ortho +lat_0=30 +lon_0=45")) + plot(p2, add = TRUE) + } } x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,10),c(0,90),c(0,0))))) # NOT long/lat: plot(x) @@ -124,8 +124,8 @@ st_sample(ls, 80) plot(st_sample(ls, 80)) # spatstat example: if (require(spatstat.random)) { - x <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 0))))) - # for spatstat.random::rThomas(), set type = "Thomas": - pts <- st_sample(x, kappa = 1, mu = 10, scale = 0.1, type = "Thomas") + x <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 0))))) + # for spatstat.random::rThomas(), set type = "Thomas": + pts <- st_sample(x, kappa = 1, mu = 10, scale = 0.1, type = "Thomas") } }