2

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)

las<-readLAS("BelottaWallaSC1.las")


head(las,10)

library(raster)

las<-data.frame(las)

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

head(rasValue,10)

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
New contributor
Alexis Londo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    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 at 22:37
  • 1
    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 at 22:38
2

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:

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

Using lidR

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

Your Answer

Alexis Londo is a new contributor. Be nice, and check out our Code of Conduct.

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.