You should check what the scale and offset are for your file. This can be done as follows:
This almost looks like an overflow error to me. The lower case x, y, and z properties need to re-scale and re-offset the coordinates to store it as an integer (which is how LAS files store them). To be honest, setting ...
According to this page, Laspy supports LAS/LAZ versions 1.0-1.4.
Looking at the Laspy code, it looks like
the format string "h6.0" would correspond to a version "1.6" of the spec.
A value of "6" for the format corresponds to a specific predefined header format. (See the code, or the following link, for clarification on what that means)
There's a good ...
I was able to come up with a solution. The following code works, but it feels like there is a much simpler way to do this operation. If anyone has a cleaner or more efficiect way to filter and reclassify lidar with laspy I'd love to accept that answer.
import numpy as np
from scipy.spatial import cKDTree
in_file = laspy.file.File(input_file, ...
Laspy isn't going to give you convenient access to the SRS in a form you can easily consume. LAS files can have either WKT or GeoTIFF keys as the coordinate system description. For consumption in Esri tools (and elsewhere), you always want the WKT.
The most convenient way to get the WKT from an LAS file is to use PDAL. The following script will read a ...
The header needs to be set with a point format that supports RGB colors, see: https://pythonhosted.org/laspy/tut_background.html. For LAS 1.2, the minimum point format for color is 2:
header = laspy.header.Header(point_format=2) # LAS point format 2 supports color
with laspy.file.File(output_path, mode="w", header=header) as lasfile:
You should use min and max property of header.
from laspy.file import File
f = File("path/to/file.laz", mode='r')
h = f.header
# h.min: [min_x, min_y, min_z] - h.max: [max_x, max_y, max_z]
extent = [*h.min, *h.max] # extent: [min_x, min_y, min_z, max_x, max_y, max_z]
LAS 1.2 has a classification byte, which is 8 bits. However 3 of those bits are used for the flags (withheld, synthetic, and keypoint).
With laspy, classification accesses the 5 bits that LAS 1.2 allows for the classification number. 2^5 is 32, meaning you can store 32 classes (0-31) in that 5-bit integer. It doesn't touch the flag bits.
This is a working solution with laspy:
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# reading las file and copy points
input_las = laspy.file.File("test.las", mode="r")
point_records = input_las.points.copy()
# getting scaling and offset parameters
las_scaleX = input_las.header.scale
So, is there a better way, more efficient, more pythonesque way of injecting the .las file points (from laspy) to the GeoPandas dataframe without passing through a numpy array?
No, and I'm not sure why you think this is the least efficient way to go. laspy is underneath the covers making a memoryview to the data and the Numpy array is a wrapper over that. ...
OK, I think I've solved my problem.
The issue is noted at the github page for laspy here:
I needed to adjust the "start_first_evlr" property to be the full length of the LAS file as shown below. Not sure if that is the best way, but it seems to work. I needed to read the mmap size for the input LAS file (before ...
The latest version of laspy will generate default file_sig = 'LASF', version_major = 1, version_minor = 2 and data_format_id = 0. However, the header offset and scale have to be specified. The following code (modified adamp's code) can generate output.las which can be read and then displayed using CloudCompare and QT Reader (The QT Reader needs minimum 4 ...
The issue was that I was not using the set method from laspy writer. I modified the Outfile.red to outfile.set_red.
This makes a nice las 1.2 file from scratch.
def write_las(self, point_array, filename, info):
#Creates las files for the calculated points and rawpoints
red, green, blue = info
As determined while working through the problem with Aaron, I figured out I was working with corrupt data, because applying the same code to other .las file worked (here is the alternative file used).
I have opened another question related to why FUSION is creating corrupt data when using the polyclipdata module here: FUSION polyclipdata creates corrupt ...
Laspy is a pythonic library for reading, modifying and writing LAS
files. Support for LAZ is limited to reading LAS version 1.0-1.3
laspy does not have support for writing files in the LAZ format.
You should be using lower-case letters for the dimensions when accessing them as floats, e.g. outfile.x instead of outfile.X.
The capitalized version is used to access the "un-scaled" dimension, which are the integers that are stored internally. Lower case should apply the scaling for you when accessing them. In your case, you're actually ...
Yogi,You can check here -https://github.com/laspy/laspy/commit/4dba4c846eacf119b5e99ccf8ccae73735ef1944. You need to write the points to an numpy array first and then write the array(X's, y's and Z's) to the file.
Read a few million points at a time and make smaller las files that you can eventually join together to make a much more massive file.
If you ...