From 15febfc4c4761506ae7cfd3d430cae6d9749275a Mon Sep 17 00:00:00 2001 From: Jean-Romain Date: Wed, 26 Jun 2024 10:58:59 -0400 Subject: [PATCH] Prepare lidR for rlas 1.7.1 --- R/io_readLAS.R | 16 +++++++++++++++- R/utils_geometry.R | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/R/io_readLAS.R b/R/io_readLAS.R index 873ee523..fc4d9866 100644 --- a/R/io_readLAS.R +++ b/R/io_readLAS.R @@ -189,6 +189,17 @@ streamLAS.LAScluster = function(x, ofile, select = "*", filter = "", filter_wkt streamLAS.character = function(x, ofile, select = "*", filter = "", filter_wkt = "") { + # Compatibility with rlas that no longer supports WKT string to filter polygons + geom = list() + if (packageVersion("rlas") > "1.7.0") + { + if (is.character(filter_wkt) && filter_wkt[1] != "") + { + geom = sf::st_as_sfc(filter_wkt) + geom = extract_polygons(geom) + } + } + assert_all_are_existing_files(x) islas <- tools::file_ext(x) %in% c("las", "laz", "ply", "LAS", "LAZ", "PLY") @@ -229,7 +240,10 @@ streamLAS.character = function(x, ofile, select = "*", filter = "", filter_wkt = } } - data <- rlas:::stream.las(ifiles, ofile, select, filter, filter_wkt) + if (packageVersion("rlas") > "1.7.0") + data <- rlas:::stream.las(ifiles, ofile, select, filter, geom) + else + data <- rlas:::stream.las(ifiles, ofile, select, filter, filter_wkt) if (is.null(data)) return(invisible()) diff --git a/R/utils_geometry.R b/R/utils_geometry.R index 282f907b..377f5774 100644 --- a/R/utils_geometry.R +++ b/R/utils_geometry.R @@ -19,6 +19,7 @@ extract_polygons = function(sfc) # Fix #763. Complex code to avoid using boost coordinates = lapply(sfc, sf::st_coordinates) rings = lapply(coordinates, extract_rings) + return(rings) } extract_rings = function(coordinates)