I found an answer that uses lastools, but unfortunately, I use a MacOS laptop, so using lastools which has its binaries in .exe format cannot be executed without some other extensions.
I'd like to shift a las file by a certain lon and lat using laspy, I've tried to update xyz and XYZ, but it doesn't seem to shift it properly. (I know this because the shifted lasfile does not align with some other layer which has been correctly georeferenced. In fact, the alignment is way off, to the point the layers don't even intersect.
Here're my codes in python, could someone give some hints/ help out in this aspect?
import laspy
shift_lat = 103.83964917-103.83963837 # Shift in latitude
shift_lon = 1.35651542-1.35653912 # Shift in longitude
# Read the input LAS file
input_file = <input>
output_file = <output>
las = laspy.read(input_file)
# Apply the shift directly to the real-world coordinates
x_shifted = las.x.copy() + shift_lon
y_shifted = las.y.copy() + shift_lat
# Create a new LAS object with the same header
output = laspy.LasData(las.header)
# Update the LAS object with the shift
output.x = x_shifted
output.y = y_shifted
output.z = las.z.copy()
# Write the shifted LAS file
output.write(output_file)
When I view the file on QGIS also, I only can see the Z values.
I am a student and have no background in geographical systems.
I tried to use offsets but to no avail.
input_las = laspy.read(input_file)
print("old offsets: ")
print(input_las.header.offsets)
output = laspy.LasData(header=input_las.header)
output.X = input_las.X
output.Y = input_las.Y
output.Z = input_las.Z
output.header.offsets = (
input_las.header.offsets[0] + shift_lat,
input_las.header.offsets[1] + shift_lon,
input_las.header.offsets[2]
)
output.write(output_file)
print("new offsets: ")
print(output.header.offsets)