Transformation Matrix (4 x 4) in lidR - Issue during export #782
Unanswered
BastienUlg
asked this question in
Q&A
Replies: 1 comment
-
Try not to use
Before to modify the point cloud, modify the header such as your # Function to apply a 4x4 transformation matrix to the point cloud
apply_transformation <- function(las, transformation_matrix)
{
# Extract point coordinates (X, Y, Z) and add a column of 1s for affine transformation
coords <- cbind(las@data$X, las@data$Y, las@data$Z, rep(1, nrow(las@data)))
# Apply the transformation matrix (matrix multiplication)
transformed_coords <- coords %*% t(transformation_matrix)
# Update the LAS object with transformed coordinates
Xt <- transformed_coords[, 1]
Yt <- transformed_coords[, 2]
Zt <- transformed_coords[, 3]
xoffset = floor(min(Xt))
yoffset = floor(min(Yt))
zoffset = floor(min(Zt))
las@header$`X offset` = xoffset
las@header$`Y offset` = yoffset
las@header$`Z offset` = zoffset
# Update the LAS object with transformed coordinates
las$X <- transformed_coords[, 1]
las$Y <- transformed_coords[, 2]
las$Z <- transformed_coords[, 3]
return(las)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use a transformation matrix like the one implemented in Cloud Compare.
When I'm applying the matrix, the X,Y and Z coordinates look fine. Yet when I'm exporting the laz point cloud using the WriteLas function, I observe a significant offset in the exported point cloud (i.e., the coordinates are different than the one I had in R - see the two pictures in attachment).
I first thought that it was a shift caused by the coordinate system but this is not the source of the issue.
Maybe it's related to the large number od decimal
value in the transformation matrix?
Potentially a header issue?
Any idea how to resolve this issue? Thanks a lot!
Here is the code with a small subset of the las file available on Gdrive:
https://drive.google.com/drive/folders/1gtf8jQjw82jWm7MjnDD97KNbL9KbH9fP?usp=sharing
Beta Was this translation helpful? Give feedback.
All reactions