I am trying to extract several point values for a set of liDAR data. I am starting with the DEM before I jump into the other more complicated values in my raster stack.

Here is my code:

library (rLiDAR)    
rasValue=extract(rasterdem,las, na.rm=TRUE)    

Here are my errors:

> rasValue=extract(rasterdem,las, na.rm=TRUE)
Error in .xyValues(x, as.matrix(y), ...) : xy should have 2 columns only.
Found these dimensions: 56159254, 5
> head(rasvalue,10)
Error in head(rasvalue, 10) : object 'rasvalue' not found
  • 2
    Please try the rlas package: CRAN.R-project.org/package=rlas rLiDAR only contains very old code that supports older LAS files and only some variants.
    – mdsumner
    Nov 7, 2019 at 22:37
  • 2
    What does that head(las, 10) show you, and what does it show after las=data.frame(las)? How many columns? To extract values from the dem you need a two-column matrix or data frame, which is what the error message is telling you. It looks like it has 5. Pick out the X and Y columns and it might work...
    – Spacedman
    Nov 7, 2019 at 22:38

1 Answer 1


I guess your are trying to get the elevation of the DEM for each point. You can do it from scratch or you can use lidR.

From scratch:

las <- read.las("pointcloud.las", select = "xyz")
dem <- raster("dem.tif")
rasValue <- extract(dem, las[,1:2])

Using lidR

las <- readLAS("pointcloud.las", select = "xyz")
dem <- raster("dem.tif")
las <- merge_spatial(las, dem, "zdem")
rasValue <- las$zdem

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.