4

I'm using the lidR package to calculate LiDAR grid metrics (p.18 documentation) for forestry applications. For example, the following calculates the mean elevation within a 20m cell:

library(lidR)

LASfile <- "/Users/aaron/Desktop/data/1958-08-53.laz"
lidar <- readLAS(LASfile)

l <- grid_metrics(lidar, mean(Z), 20)

I can plot the results using the following approach:

grid_metrics(lidar, mean(Z), 20) %>% plot

What is the proper method to write the grid metrics to a georeferenced raster (e.g. geotiff)?

5

In lidR package there is a function as.raster which is faster than rasterFromXYZ

r <- as.raster(l)

If l is several columns wide (more than one metric), the output is a RasterStack instead of a RasterLayer

5

Since the output is a dataframe with X,Y coordinates and a value (V1) column, you can use rasterFromXYZ from the raster package. Then write to GeoTIFF format using writeRaster, also from the raster package.

library(lidR)
library(raster)

LASfile <- "/Users/aaron/Desktop/temp/lidR_gridmetrics/1958-08-53.las"
lidar <- readLAS(LASfile)

l <- grid_metrics(lidar, mean(Z), 20) 

r <- rasterFromXYZ(l, crs='+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs ')
writeRaster(r, filename="/Users/aaron/Desktop/temp/lidR_gridmetrics/1958-08-53.tif", format="GTiff", overwrite=TRUE)

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.