r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
587 stars 132 forks source link

Item 2 of j is 4 which is outside the column number range [1,ncol=2] #663

Closed flottsam closed 1 year ago

flottsam commented 1 year ago

I'm trying to segment a las catalog and not sure how to interpret the error message:

error occurred when processing the chunk 6. Try to load this chunk with:
 chunk <- readRDS(...) 
las <- readLAS(chunk)
Item 2 of j is 4 which is outside the column number range [1,ncol=2]

This particular tile has powerlines in it, which I suspect may be the issue.

To find the trees, I used: (trees <- locate_trees(ctg, algorithm = lmfauto(), uniqueness = "bitmerge"))

And to segment:

dir.create(here("als/4_segmented"))
opt_filter(ctg) <- "-drop_z_below 0 -drop_class 2"
opt_output_files(ctg) <- here("als/4_segmented/{ORIGINALFILENAME}")
opt_laz_compression(ctg) <- FALSE # output .laz or .las?
plan(multisession, workers = detectCores(logical = FALSE)/2) # use 1/2 physical cores
# run function 
silva <- silva2016(chm=chm, treetops = trees)
segment_trees(ctg, algorithm = silva, attribute = "treeID", uniqueness = "bitmerge")

Sometimes the error message is returned on a different tile. They are always (so far) tiles on the edge of the catalog.

image

Jean-Romain commented 1 year ago

I don't know what is the error. You must provide a reproductible exemple. When failing the LAScatalog processing engine save the chunk that failed in a temp file. You can read it and run the function on this particular chunk to reproduce the exact condition that lead to a crash.

chunk <- readRDS(...) 
las <- readLAS(chunk)
silva <- silva2016(chm=chm, treetops = trees)
segment_trees(las, algorithm = silva, attribute = "treeID", uniqueness = "bitmerge")

If the error is reproductible, you must send me some data so I can reproduce.

Thanks

flottsam commented 1 year ago

.

flottsam commented 1 year ago

.

flottsam commented 1 year ago

.

flottsam commented 1 year ago

.

flottsam commented 1 year ago

Sorry to bombard you with so many replies, but the problem appears to be related to the tiles that do not spatially intersect w/ the CHM. Below better visualizes the problem. I first use trees <- locate_trees(chm, lmf(f)). Then, I subset the CTG with ctg_subset <- catalog_select(ctg, chm), and then ctg_trees <- segment_trees(ctg_subset, silva2016(chm, trees)), and get the results below (_Warning: _1: No tree can be used as seed__ ). Orange tiles do not have trees because the CHM does not exist there

image

The problem is when I try to delineate crowns from the newly segmented CTG. crowns <- crown_metrics(ctg_trees, func = .stdtreemetrics, geom = "concave"), because there are no trees in those tiles that do intersect spatially with the CHM. image

Jean-Romain commented 1 year ago

I appreciate that you are trying to provide many details. However as you said, you bombarded me we data. At this stage I'm no longer able to sort out all the data you gave me.

Can you produce a clean and tidy minimal reproducible example using a small data file ? If the problem comes from seeds, chm and tiles that do not match I guess it should be easy to reproduce with the data shipped with the package.

flottsam commented 1 year ago

I subset the ctg using a shapefile rather than the chm and was able to process w/o error. image