rlidr

How to solve Error at lidR::delineate_crowns?


Processing a script I wrote a couple of month ago with an older version old lidR causes an error with current version. name of functions changed from lidR::tree_hulls to lidR::delineate_crowns

It worked with the old version but doesn't with the new version.

sample data: https://github.com/anayana/so_sampla_data/blob/main/so_sample_las.laz (there might be better ways to share data, tips are welcome)

sample code:

so_sample_las <- readLAS("so_sample_las.laz")
tree.hulls <- lidR::delineate_crowns(clean_las, type="concave", attribute="treeID") 
  

error message

Error in (function (cond)  : 
                error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': Evaluation error:
IllegalArgumentException: Invalid number of points in LinearRing found 3 - must be 0 or >= 4.

what I tried:

remove all points that belong to a treeID which is represented by less than 4 entries
create LAS without points of underrepresented treeIDs

so_sample_las_dat <- so_sample_las@data
clean_dat <- las.so_sample_las_dat [so_sample_las_dat $treeID %in% names(which(table(so_sample_las_dat $treeID) > 4)), ]

clean_las <- so_sample_las
clean_las@data <- clean_dat
clean_tree.hulls <- lidR::delineate_crowns(clean_las, type="concave", attribute="treeID")

error message

Error in (function (cond)  : 
                error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': Evaluation error:
IllegalArgumentException: Invalid number of points in LinearRing found
3 - must be 0 or >= 4.

same error message appeared. Maybe I don't understand the error message or did another mistake. any hint is welcome!


Solution

  • I tested both with delineate_crown() (deprecated) and crown_metrics(). Both work. delineate_crown() produces warnings but they can be ignored.

    library(lidR)
    so_sample_las <- readLAS("so_sample_las.laz")
    tree.hulls.1 <- delineate_crowns(so_sample_las, type="concave", attribute="treeID") 
    tree.hulls.2 <- crown_metrics(so_sample_las,  func = NULL,  geom = "concave", attribute = "treeID")
    

    Update your packages and if you still encounter troubles report a bug.