I am trying to get the number of pulse at different height interval.

I have used the lidR package to do this before with the code below but it seems that recent update in the package breaks my code. My main error is that when I run the function I get an error that says the ScanAngle and PulseID no longer exist. Any help on which function I should use now?

The following code used to work:

# the number of points is computed.
grid_metrics3d(lidar1, length(Z),res = 0.5)

# Cloud of points is voxelized with a 1-meter resolution and in each voxel
# the mean scan angle of points is computed.
grid_metrics3d(lidar1, mean(Angle),res = 0.5)

# Define your own metric function
myMetrics = function(i, ScanAngleRank, PointSourceID)
  ret = list(
   npulse  = length(unique(PointSourceID)),
   angle   = mean(ScanAngleRank),
   imean   = mean(i))


voxels1 = grid_metrics3d(lidar1, myMetrics(Intensity, ScanAngle, PointID ),res = 0.5)
| improve this question | | | | |

You were almost there. You missed to compute the pulseID with laspulse() and you missed that the scan angle is stored in ScanAngleRank

Since lidR 2.0.0 pulseID is no longer computed at read time. And since rlas 1.3.0 that introduced support of LAS 1.4 format the attribute ScanAngle is now ScanAngleRank. The name ScanAngle is reserved for angle stored in LAS 1.4 format. This latest modification is known to break former codes like yours but was required to better fit with LAS specifications

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las = readLAS(LASfile)
las = laspulse(las)

myMetrics = function(I, A, ID)
  ret = list(
    npulse  = length(unique(ID)),
    angle   = mean(A),
    imean   = mean(I))


voxels1 = grid_metrics3d(las, ~myMetrics(Z, ScanAngleRank, pulseID), res = 10)
plot(voxels1, "npulse")

Also notice that PointSourceID is not at all related to your question. PointSourceID usually records an ID for each flightline

| improve this answer | | | | |

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.