LaspyException: Invalid file signature "b'\xca\x8d\xa0?'" (trying to convert .laz to .las using phyton)

396 Views Asked by At

I got an error trying to run the code below. The code tries to convert a .laz file into a .las file. The first file with the name 06bn1 has no trouble converting, but other files give the error message:

LaspyException: Invalid file signature "b'\xca\x8d\xa0?'"

changing the names does not solve the problem, and running the files individually also does not work. the code I used:

def laz_to_las(kaartbladen):
for k in kaartbladen:
file_path_laz =  os.path.join('TEMP',str(k.upper())+".LAZ")
file_path =  os.path.join('TEMP',str(k.upper())+".LAS")
if not os.path.exists(file_path):  
print("converting " + k)
las = laspy.read(file_path_laz)
las = laspy.convert(las)
las.write(file_path)
print("laz to las convert complete!")
print("all maps converted")
laz_to_las(\["06BN1","06BN2","06BN2"\])

The error message:

LaspyException Traceback (most recent call last) <ipython-input-2-4ea8b8d3235b> in <module> ----> 1 laz_to_las(["06BN1","06BN2","06BN2"])

<ipython-input-1-91b572718729> in laz_to_las(kaartbladen) 91 if not os.path.exists(file_path): 92 print("converting " + k) ---> 93 las = laspy.read(file_path_laz) 94 las = laspy.convert(las) 95 las.write(file_path)

~\AppData\Roaming\Python\Python38\site-packages\laspy\lib.py in read_las(source, closefd, laz_backend) 185 The object you can interact with to get access to the LAS points & VLRs 186 """ --> 187 with open_las(source, closefd=closefd, laz_backend=laz_backend) as reader: 188 return reader.read() 189

~\AppData\Roaming\Python\Python38\site-packages\laspy\lib.py in open_las(source, mode, closefd, > laz_backend, header, do_compress, encoding_errors) 116 else: 117 stream = source --> 118 return LasReader(stream, closefd=closefd, laz_backend=laz_backend) 119 elif mode == "w": 120 if header is None:

~\AppData\Roaming\Python\Python38\site-packages\laspy\lasreader.py in init(self, source, closefd, laz_backend) 47 laz_backend = LazBackend.detect_available() 48 self.laz_backend = laz_backend ---> 49 self.header = LasHeader.read_from(source, read_evlrs=True) 50 51 if self.header.point_count > 0:

~\AppData\Roaming\Python\Python38\site-packages\laspy\header.py in read_from(cls, original_stream, read_evlrs) 531 header = cls() 532 --> 533 stream = io.BytesIO(cls._prefetch_header_data(original_stream)) 534 535 file_sig = stream.read(4)

~\AppData\Roaming\Python\Python38\site-packages\laspy\header.py in _prefetch_header_data(source) 851 raise LaspyException(f"Source is empty") 852 if file_sig != LAS_FILE_SIGNATURE: --> 853 raise LaspyException(f'Invalid file signature "{file_sig}"') 854 if len(header_bytes) < LAS_HEADERS_SIZE["1.1"]: 855 raise LaspyException("File is to small to be a valid LAS")

LaspyException: Invalid file signature "b'\xca\x8d\xa0?'"

0

There are 0 best solutions below