2

I use the pitfree algorithm to create the CHM of 89 .LAS files.

chm = grid_canopy(lasnorm, 0.5, pitfree(thresholds = c(0,2,5,10,15,20), subcircle = 0.2))

In the entire code, I go trough each files to produce a segmentation raster with some metrics. Depending on the settings I use for the pitfree algorithm, I will get an error on different LAS files.

I tried to change the parameters (resolution, subcircle, thresholds), but each time I would end out having that same error ("Not a matrix"), although, not for the same .LAS. I did not play much with the max_edge argument because I am not yet entirely sure of how it affects the algorithm.

The error I get from running the code in a loop (tSearch()) seems to refer to the triangulation part of the code.

Here's the error I would get running the code with a loop

Error in tSearch(D, P, X, threads) : Not a matrix.

Here's the error I would get running the code with LAScatalog

 An error occurred when processing the chunk 7. Try to load this chunk with:
 chunk <- readRDS("...\AppData\Local\Temp\RtmpQ3rscv/chunk7.rds")
 las <- readLAS(chunk)
 Not a matrix.

I would like to know what I should look into to avoid this error but keep the same parameters for all my .LAS?

As suggested, I tried manipulating the chunk from the error. I put here my results in case it can be useful.

I am able to run pitfree() on it with different parameters (las is the chunk):

chm18 = grid_canopy(las, 0.5, pitfree(c(0,2,5,10,15,20))) #Without subcircle (error)
Error in tSearch(D, P, X, threads) : Not a matrix.

chm18 = grid_canopy(las, 0.5, pitfree(c(0,2,5,10,15,20), subcircle = 0.2)) #with subcircle (works)
chm18 = grid_canopy(las, 0.25, pitfree(c(0,2,5,10,15,20))) #res to 0.25 (works)
chm18 = grid_canopy(las, 1, pitfree(c(0,2,5,10,15,20))) #res to 1 (works)

I tried with the edge parameters too.

chm18 = grid_canopy(las, 0.5, pitfree(c(0,2,5,10,15,20), c(0,1)))
Error in tSearch(D, P, X, threads) : Not a matrix.

c(0,3), c(2,3), c(0,4) all worked though

Lastly, I changed the thresholds values :

chm19 = grid_canopy(las3, 0.5, pitfree(c(0,2,5,10))) #removed the 2 last tresholds (works)

chm19 = grid_canopy(las3, 0.5, pitfree(c(0,2,5,10,14))) #tried last threshold set other than 15 (works)

Any threshold other that 15 would work (10,11,12,13,14,16,17,18,19,20)

  • There is clearly something that should be handled internally. What you should do first is to load the chunk number 7 and look the point cloud. Does it look good? Is there something special in it? Can you manage to run pitfree() on it. Bad parameters should fail with an error like Interpolation failed. Input parameters might be wrong. Here you found a limit case. I tested everything I can without being able to reproduce. If you think it is a bug please report with a reproducible example. – JRR Oct 9 at 13:21
  • I looked the chunks point cloud and it seems normal to me. I also compared with other 5 files that gives the same error and I can't see something that make them different from other files. I have updated the original post with some info and results of playing around with the algorithm to see what works and what doesn't. Unfortunately, I cannot share the data to make it reproducible. I'll look what I can do if you think it would be useful to correct a bug or something. – Hereshk Oct 9 at 19:21
  • You definitively found a bug. Please communicate with me preferably on github if possible or by email. We will try to reproduce and fix. – JRR Oct 9 at 21:14
  • Could you please mention which version of the package your are using – JRR Oct 10 at 8:53
  • Version is 2.1.3. I will get back to you for the files. – Hereshk Oct 10 at 10:14
1

This was a bug fixed in version 2.1.4. In short in R when you subset a matrix you get a matrix (that makes sense) but when you subset a single row you get a vector instead of a 1 x n matrix. R's behavior is inconsistent. In rare cases you may have a single remaining triangle in pitfree(). This is why you got an internal error not a matrix. This case is now handled.

  • I can confirm that it is working with my data as well after I updated to 2.1.4. Glad someone was able to provide you a reproducible example. – Hereshk Oct 15 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.