0

I am trying to calculate the proportion of points 0.3-2.5m above ground relative to the number of ground points + all points up to 2.5m above ground using lidR grid_metrics(). My custom grid_metrics() calculation works on the lidR demo data provided with the package ("MixedConifer.laz") but fails to work with the data I'm interested in using (New Brunswick, Canada LiDAR tiles).

More specifically, this code successfully produces the metric:

require(lidR)
library(raster)

# read in demo file from lidR package
LASfile <- system.file("extdata", "MixedConifer.laz", package ="lidR")
las <- readLAS(LASfile)

shrub_cover = function(z) {
  n_shrub = sum(z >= 0.3 & z <= 2.5)
  n_veg = sum(z <= 2.5)
  return(list(ratio = n_shrub/n_veg))
}

shrub_cover_metric = grid_metrics(las, ~shrub_cover(Z), res = 10)
writeRaster(shrub_cover_metric, "data/interim/shrub_cover_demo_tile.tif", overwrite=TRUE)

But this script does not... the data I'm working with can be accessed here

las <- readLAS("C:/Users/pende/Downloads/nb_2018_2573000_7416000.laz")

shrub_cover = function(z) {
  n_shrub = sum(z >= 0.3 & z <= 2.5)
  n_veg = sum(z <= 2.5)
  return(list(ratio = n_shrub/n_veg))
}

shrub_cover_metric = grid_metrics(las, ~shrub_cover(Z), res = 10)
writeRaster(shrub_cover_metric, "data/interim/shrub_cover_nb_2018_2573000_7416000.tif", overwrite=TRUE)

I've tried removing duplicate points in the nb_2018_2573000_7416000.laz data, but this doesn't change the output result of a raster full of -Inf data.

What is causing this issue? The grid_metrics() function is the same...

3
  • What is the error ?
    – JRR
    Commented Mar 1, 2023 at 18:39
  • There isn't an error message.. I find out that the raster is infinite by viewing it in ArcGIS. BUT.. I fixed my own problem! I forgot to normalize the points! I will submit an answer below.
    – Jocelyn P.
    Commented Mar 1, 2023 at 18:44
  • That was my next question
    – JRR
    Commented Mar 1, 2023 at 18:46

1 Answer 1

0

The data I was working with contained raw elevation values and not heights above ground. To solve my problem, I needed to normalize my points. This is the script that is now working:

require(lidR)
library(raster)

las <- readLAS("C:/Users/pende/Downloads/nb_2018_2573000_7416000.laz")
nlas <- normalize_height(las, tin())

shrub_cover = function(z) {
  n_shrub = sum(z >= 0.3 & z <= 2.5)
  n_veg = sum(z <= 2.5)
  return(list(ratio = n_shrub/n_veg))
}

shrub_cover_metric = grid_metrics(nlas, ~shrub_cover(Z), res = 10)
writeRaster(shrub_cover_metric, "data/interim/shrub_cover_nb_2018_2573000_7416000.tif", overwrite=TRUE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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