v4.0.0
lidR v4.0.0 (Release date: 2022-02-17)
rgdal
and rgeos
will be retired on Jan 1st 2024. see twitter, youtube, or see the respective package descriptions on CRAN. Packages raster
and sp
are based on rgdal
/rgeos
and lidR
was based on raster
and sp
because it was created before sf
, terra
and stars
. This means that sooner or later lidR
will run into trouble (actually it is more or less already the case). Consequently, we modernized lidR
by moving to sf
, terra
/stars
and we are no longer depending on sp
and raster
(see also Older R Spatial Package for more insight). It is time for everybody to stop using sp
and raster
and to embrace sf
and stars/terra
.
In version 4 lidR
now no longer uses sp
, it uses sf
and it no longer uses raster
. It is now raster agnostic and works transparently with rasters from raster
, terra
and stars
. These two changes meant we had to rewrite a large portion of the code base, which implies few backward incompatibilities. The backward incompatibilities are very small compared to the huge internal changes we implemented in the foundations of the code and should not even be visible for most users.
Backward inconpatibilites
-
lidR
no longer loadsraster
andsp
. To manipulateRaster*
andSpatial*
objects returned by lidR users need to loadsp
andraster
with:library(sp) library(raster) library(lidR)
-
The formal class
LAS
no longer inherits the classSpatial
fromsp
. It means, among other things, that aLAS
object no longer has a slot@proj4string
with aCRS
fromsp
, or a slot@bbox
. The CRS is now stored in the slot@crs
in acrs
object fromsf
. Former functionscrs()
andprojection()
inherited fromraster
are backward compatible and return aCRS
or aproj4string
fromsp
. However code that accesses these slots manually are no longer valid (but nobody was supposed to do that anyway because it was the purpose of the functionprojection()
):las@proj4string # No longer works las@bbox # No longer works inherits(las, "Spatial") # Now returns FALSE
-
The formal class
LAScatalog
no longer inherits the classSpatialPolygonDataFrame
fromsp
. It means, among other things, that aLAScatalog
object no longer has a slot@proj4string
, or@bbox
, or@polygons
. The slot@data
is preserved and contains ansf,data.frame
instead of adata.frame
allowing backward compatibility of data access to be maintained. The syntaxctg$attribute
is the way to access data, but statement likectg@data$attribute
are backward compatible. However, code that accesses other slots manually is no longer valid, like for theLAS
class:ctg@proj4string # No longer works ctg@bbox # No longer works ctg@polygons # No longer works inherits(ctg, "Spatial") # Now returns FALSE
-
sp::spplot()
no longer works on aLAScatalog
because aLAScatalog
is no longer aSpatialPolygonDataFrame
spplot(ctg, "Max.Z") # becomes plot(ctg["Max.Z"])
-
raster::projection()
no longer works onLAS*
objects because they no longer inheritSpatial
. Moreover,lidR
no longerDepends
onraster
which means thatraster::projection()
andlidR::projection
can mask each other. Users should usest_crs()
preferentially. To useprojection
users can either loadraster
beforelidR
or calllidR::projection()
with the explicit namespace.library(lidR) projection(las) # works library(raster) projection(las) # no longer works
-
Serialized
LAS/LAScatalog
objects (i.e. stored in.rds
or.Rdata
files) saved withlidR v3.x.y
are no longer compatible withlidR v4.x.y
. Indeed, the structure of aLAS/LAScatalog
object is now different mainly because the slot@crs
replaces the slot@proj4string
. Users may get errors when using e.g.readRDS(las.rds)
to load back an R object. However we put safeguards in place so, in practice, it should be backward compatible transparently, and even repaired automatically in some circumstances. Consequently we are not sure it is a backward incompatibility because we handled and fixed all warnings and errors we found. In the worst case it is possible to repair aLAS
object v3 with:las <- LAS(las)
-
track_sensor()
is not backward compatible because it is a very specific function used by probably just 10 people in the world. We chose not to rename it. It now returns ansf
object instead of aSpatialPointsDataFrame
.
New modern functions
Former functions that return Spatial*
objects from package sp
should no longer be used. It is time for everybody to embrace sf
. However, these functions are still in lidR
for backward compatibility. They won't be removed except if package sp
is removed from CRAN. It might happen on Jan 1st 2024, it might happen later. We do not know. New functions return sf
or sfc
objects. Old functions are not documented so new users won't be able to use them.
tree_metrics()
anddelineate_crowns()
are replaced by a single functioncrown_metrics()
that has the same functionality, and more.find_trees()
is replaced bylocate_trees()
.
Older functions that return Raster*
objects from the raster
package should no longer be used. It is time for everybody to embrace terra/stars
. However, these functions are still in lidR
for backward compatibility. They won't be removed except if package raster
is removed from CRAN. New functions return either a Raster*
, a SpatRaster
, or a stars
object, according to user preference.
grid_metrics()
is replaced bypixel_metrics()
grid_terrain()
,grid_canopy()
,grid_density()
are replaced byrasterize_terrain()
,rasterize_canopy()
,rasterize_density()
New features
New functions are mostly convenient features that simplify some workflow aspects without introducing a lot of brand new functionality that did not already exist in lidR
v3.
-
New geometry functions
st_convex_hull()
andst_concave_hull()
that returnsfc
-
New modern functions
st_area()
,st_bbox()
,st_transform()
andst_crs()
inherited fromsf
forLAS*
objects. -
New convenient functions
nrow()
,ncol()
,dim()
,names()
inherited frombase
forLAS*
objects -
New operators
$
,[[
,$<-
and[[<-
onLASheader
. The following are now valid statements:header[["Version Major"]] header[["Z scale factor"]] <- 0.001
-
Operators
$
,[[
,$<-
and[[<-
onLAS
can now access theLASheader
metadata. The following are now valid statements:las[["Version Major"]] las[["Z scale factor"]] <- 0.001
-
RStudio now supports auto completion for operator
$
inLAS
objects. Yay! -
New functions
template_metrics()
,hexagon_metrics()
,polygon_metrics()
that extend the concept of metrics further to any kind of template. -
Functions that used to accept spatial vector or spatial raster as input now consistently accept any of
Spatial*
,sf
,sfc
,Raster*
,SpatRaster
andstars
objects. This includemerge_spatial()
,normalize_intensity()
,normalize_height()
,rasterize_*()
,segment_trees()
,plot_dtm3d()
and several others. We plan to supportSpatVector
in future releases. -
Every function that supports a raster as input now accept an "on-disk" raster from
raster
,terra
andstars
i.e. a raster not loaded in memory. This includes rasterization functions, individual tree segmentation functions,merge_spatial
and others, in particularplot_dtm3d()
andadd_dtm3d()
that now downsample on-disk rasters on-the-fly to display very large DTMs. On-disk rasters were already generally supported in previous versions but not every function was properly optimized to handle such objects. -
All the functions that return a raster (
pixel_metrics()
andrasterize_*()
) are raster agnostic and can return rasters fromraster
,terra
orstars
. They have an argumentpkg = "raster|terra|stars"
to choose. The default isterra
but this can be changed globally using:options(lidR.raster.default = "stars")
-
New function
catalog_map()
that simplifiescatalog_apply()
to a large degree. Yet it is not as versatile ascatalog_apply()
but well suits around 80% of use cases. Applying a user-defined function to a collection of LAS files is now as simple as:my_fun <- function(las, ...) { # do something with the point cloud return(something) } res <- catalog_map(ctg, my_fun, param1 = 2, param2 = 5)
-
Operator
[
onLAS
object has been overloaded to clip a point-cloud using abbox
or asfc
sub <- las[sfc]
-
rasterize_terrain()
accepts ansfc
as argument to force interpolation within a defined area. -
normalize_height()
now always interpolates all points. It is no longer possible to get an error that some points cannot be interpolated. The problem of interpolating the DTM where there is no data is still present but we opted for a nearest neighbour approach with a warning instead of a failure. This prevents the method from failing after hours of computation for special cases somewhere in the file collection. This also means we removed thena.rm
option that is no longer relevant. -
New functions
header()
,payload()
,phb()
,vlr()
,evlr()
to get the corresponding data from aLAS
object. -
New algorithm
shp_hline
andshp_vline
forsegment_shapes()
#499 -
New algorithm
mcc
for ground classification.
Enhancement
-
The bounding box of the CHM computed with
rastertize_canopy()
orgrid_canopy()
is no longer affected by thesubcircle
tweak. See #518. -
readLAS()
can now read two or more files that do not have the same point format (see #508) -
plot()
forLAS
gains argumentspal
,breaks
andnbreaks
similar tosf
. Argumentstrim
andcolorPalette
are deprecated
Fix
- The metric
itot
fromstdmetrics_i
which generates troubles (see #463 #514) is nowdouble
instead ofint
Documentation
- Man pages of
classify_*
,rasterize_*
,*_metrics
,segment_*
andnormalize_*
were grouped. - The pdf version of the manual contains more documentation (more functions) but is 20 pages shorter, meaning that we tidied and cleaned up the documentation.