rspatial / raster

R raster package https://rspatial.github.io/raster/reference/raster-package.html
GNU General Public License v3.0
161 stars 53 forks source link

Error in locating/segmenting trees from vegetation subset and existing " unreadable" CHM with "no matching extents" (NA values) #316

Closed colinfabre closed 8 months ago

colinfabre commented 1 year ago

Hi,

I have a bunch of point clouds to process (~900) to build a validation dataset. I need to compute different tree-level and stand-level metrics, so start my analysis by locating and segmenting trees in each cloud with its existing CHM, using the lidR package. CHMs were produced upstream, only accounting for vegetated areas (based on point classification) - therefore many of them end up in having NA values (everywhere where it's not vegetation) and it may be the case all along the cloud length or width. When I try to load the existing CHM for the currently processed LAS file with raster::raster, the function fails as it cannot read the CHM file:

Error in validityMethod(object) : invalid extent: xmin >= xmax

When I use View(CHM), the TIF file shows a correct extent (with xmin < xmax and ymin < ymax), but raster::raster seems to fail because of NA values on the edge of the CHM, resulting in an impossible extent calculation as sub-task of raster::raster function. I tried to bypass this error by assigning a defined NA value (-9999) to NA values, but cannot even do that as the CHM won't load at all. Given the number of point clouds and their size, I cannot afford a CHM recalculation on the hole cloud (regardless point cloud classification) within my last 2 weeks of contract.

I also get additional warnings regarding min and max values, but I don't think it will impact further analysis:

In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf

Please find attached my R script. mean_diameter.txt

Originally posted by @colinfabre in https://github.com/r-lidar/lidR/discussions/695

rhijmans commented 11 months ago

There is not much (no example, no data) here that I can respond to.