Skip to content

Commit

Permalink
Fix for no_suggest
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Romain committed Jun 17, 2024
1 parent 2a3d44d commit 82ba3b1
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 11 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ If you are viewing this file on CRAN, please check [the latest news on GitHub](h
- Enhance: `decimate_points()` with `random()` now preserves the point ordering.
- Fix: #757
- Fix: algorithm `random_per_voxel` that was not working
- Fix: `readLAScatalog` if `sp` is missing

## lidR v4.1.1 (Release date: 2024-02-03)

Expand Down
21 changes: 13 additions & 8 deletions R/Class-LAScatalog.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ setMethod("initialize", "LAScatalog", function(.Object)
{
Raster = NULL
stars = NULL
spatial = NULL

if (system.file(package='raster') != "")
if (system.file(package='raster') != "" && system.file(package='sp') != "")
{
Raster = list(
write = raster::writeRaster,
Expand All @@ -201,9 +202,20 @@ setMethod("initialize", "LAScatalog", function(.Object)
param = list(NA_value = -999999))
}

if (system.file(package='sp') != "")
{
spatial = list(
write = writeSpatial,
extension = ".shp",
object = "x",
path = "filename",
param = list(overwrite = FALSE))
}

drivers = list(
Raster = Raster,
stars = stars,
Spatial = spatial,
SpatRaster = list(
write = terra::writeRaster,
extension = ".tif",
Expand All @@ -226,13 +238,6 @@ setMethod("initialize", "LAScatalog", function(.Object)
path = "file",
param = list()
),
Spatial = list(
write = writeSpatial,
extension = ".shp",
object = "x",
path = "filename",
param = list(overwrite = FALSE)
),
sf = list(
write = sf::st_write,
extension = ".shp",
Expand Down
6 changes: 6 additions & 0 deletions R/algorithm-gnd.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@
#' @family ground segmentation algorithms
#'
#' @examples
#' if (require(RMCC, quietly = TRUE))
#' {
#' LASfile <- system.file("extdata", "Topography.laz", package="lidR")
#' las <- readLAS(LASfile, select = "xyzrn", filter = "-inside 273450 5274350 273550 5274450")
#'
#' las <- classify_ground(las, mcc(1.5,0.3))
#' #plot(las, color = "Classification")
#' }
#' @export
#' @name gnd_mcc
mcc <- function(s = 1.5, t = 0.3)
Expand Down Expand Up @@ -180,12 +183,15 @@ pmf = function(ws, th)
#' @family ground segmentation algorithms
#'
#' @examples
#' if (require(RCSF, quietly = TRUE))
#' {
#' LASfile <- system.file("extdata", "Topography.laz", package="lidR")
#' las <- readLAS(LASfile, select = "xyzrn")
#'
#' mycsf <- csf(TRUE, 1, 1, time_step = 1)
#' las <- classify_ground(las, mycsf)
#' #plot(las, color = "Classification")
#' }
#' @name gnd_csf
csf = function(sloop_smooth = FALSE, class_threshold = 0.5, cloth_resolution = 0.5, rigidness = 1L, iterations = 500L, time_step = 0.65)
{
Expand Down
4 changes: 3 additions & 1 deletion R/catalog_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#'
#' - It represents a chunk of the file collection
#' - The function \link{readLAS} can be used with a `LAScluster`
#' - The function \link[raster:extent]{extent} or \link[sp:bbox]{bbox} or \link[sf:st_bbox]{st_bbox}
#' - The function \link[raster:extent]{extent} or \link[sf:st_bbox]{st_bbox}
#' can be used with a `LAScluster` and they return the bounding box of the chunk without the buffer.
#' It must be used to clip the output and remove the buffered region (see examples).
#'
Expand Down Expand Up @@ -210,7 +210,9 @@
#' # 4. Apply a user-defined function to take advantage of the internal engine
#' opt <- list(need_buffer = TRUE) # catalog_apply will throw an error if buffer = 0
#' output <- catalog_map(ctg, my_tree_detection_method, ws = 5, .options = opt)
#' }
#'
#' \dontrun{
#' ## ===================================================
#' ## Example 2: compute a rumple index on surface points
#' ## ===================================================
Expand Down
3 changes: 3 additions & 0 deletions R/classify.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@
#' # Classify ground
#' # ===============
#'
#' if (require(RCSF, quietly = TRUE))
#' {
#' LASfile <- system.file("extdata", "Topography.laz", package="lidR")
#' las <- readLAS(LASfile, select = "xyzrn", filter = "-inside 273450 5274350 273550 5274450")
#'
#' # (Parameters chosen mainly for speed)
#' mycsf <- csf(TRUE, 1, 1, time_step = 1)
#' las <- classify_ground(las, mycsf)
#' #plot(las, color = "Classification")
#' }
#'
#' # ===============
#' # Classify noise
Expand Down
3 changes: 3 additions & 0 deletions R/metrics_stdmetrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ NULL
#' x <- runif(20, 0, 100)
#' y <- runif(20, 0, 100)
#'
#' if (require(geometry, quietly = TRUE))
#' {
#' # Perfectly flat surface, rumple_index = 1
#' z <- rep(10, 20)
#' rumple_index(x, y, z)
Expand All @@ -456,6 +458,7 @@ NULL
#' # Measure of roughness is scale-dependent
#' rumple_index(x, y, z)
#' rumple_index(x/10, y/10, z)
#' }
#' @md
#' @references
#' Jenness, J. S. (2004). Calculating landscape surface area from digital elevation
Expand Down
3 changes: 2 additions & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ plot.LAScatalog = function(x, y, mapview = FALSE, chunk_pattern = FALSE, overlap
if (is.null(param$ylab)) param$ylab <- ""
if (is.null(param$asp)) param$asp <- 1
if (!is.null(param$col)) col <- param$col
param$map.types = NULL

param$col <- "white"
param$x <- xcenter
Expand All @@ -215,7 +216,7 @@ plot.LAScatalog = function(x, y, mapview = FALSE, chunk_pattern = FALSE, overlap
}
else
{
plot(as.spatial(x), col = col)
plot(sf::st_geometry(sf::st_as_sf(x)), axes = TRUE)
graphics::par(op)
}

Expand Down
4 changes: 3 additions & 1 deletion man/catalog_apply.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/classify.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/gnd_csf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/gnd_mcc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/nstdmetrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/testthat/test-classify_ground.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ test_that("classify_ground pmf works with LAScatalog", {
})

test_that("classify_ground csf works with LAS", {

skip_if_not_installed("RCSF")

las <- classify_ground(las, mycsf)

n = names(las)
Expand All @@ -51,6 +54,8 @@ test_that("classify_ground csf works with LAS", {
})

test_that("classify_ground csf works with LAScatalog", {

skip_if_not_installed("RCSF")
skip_on_cran()

opt_output_files(ctg) <- paste0(tempdir(), "/file_{XLEFT}_{YBOTTOM}_ground")
Expand All @@ -63,6 +68,9 @@ test_that("classify_ground csf works with LAScatalog", {
})

test_that("classify_ground csf works with last_returns = FALSE", {

skip_if_not_installed("RCSF")

las <- lidR:::generate_las(500)
las <- classify_ground(las, csf(), last_returns = FALSE)

Expand All @@ -74,6 +82,9 @@ test_that("classify_ground csf works with last_returns = FALSE", {
})

test_that("classify_ground works with last_returns = TRUE but attribute not properly populated", {

skip_if_not_installed("RCSF")

las <- lidR:::generate_las(500)
las@data$ReturnNumber <- 0
las@data$Classification <- NULL
Expand Down

0 comments on commit 82ba3b1

Please sign in to comment.